Java Code Examples for com.twitter.util.Duration#apply()

The following examples show how to use com.twitter.util.Duration#apply() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OstrichAdminService.java    From doctorkafka with Apache License 2.0 6 votes vote down vote up
public void startAdminHttpService() {
  try {
    Properties properties = new Properties();
    properties.load(this.getClass().getResource("build.properties").openStream());
    LOG.info("build.properties build_revision: {}",
        properties.getProperty("build_revision", "unknown"));
  } catch (Throwable t) {
    LOG.warn("Failed to load properties from build.properties", t);
  }
  Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
  Iterator<Duration> durationIterator = Arrays.asList(defaultLatchIntervals).iterator();
  @SuppressWarnings("deprecation")
  AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
      this.port,
      20,
      List$.MODULE$.empty(),
      Option.empty(),
      List$.MODULE$.empty(),
      Map$.MODULE$.empty(),
      JavaConversions.asScalaIterator(durationIterator).toList());
  RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
  AdminHttpService service = adminServiceFactory.apply(runtimeEnvironment);
  for (Map.Entry<String, CustomHttpHandler> entry : this.customHttpHandlerMap.entrySet()) {
    service.httpServer().createContext(entry.getKey(), entry.getValue());
  }
}
 
Example 2
Source File: OstrichAdminService.java    From terrapin with Apache License 2.0 6 votes vote down vote up
public void start() {
  Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
  @SuppressWarnings("deprecation")
  AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
      this.mPort,
      20,
      List$.MODULE$.<StatsFactory>empty(),
      Option.<String>empty(),
      List$.MODULE$.<Regex>empty(),
      Map$.MODULE$.<String, CustomHttpHandler>empty(),
      List.<Duration>fromArray(defaultLatchIntervals));
  RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
  AdminHttpService service = adminServiceFactory.apply(runtimeEnvironment);
  for (Map.Entry<String, CustomHttpHandler> entry: this.mCustomHttpHandlerMap.entrySet()) {
    service.httpServer().createContext(entry.getKey(), entry.getValue());
  }
}
 
Example 3
Source File: OstrichAdminService.java    From pinlater with Apache License 2.0 6 votes vote down vote up
public void start() {
  Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
  @SuppressWarnings("deprecation")
  AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
      this.mPort,
      20,
      List$.MODULE$.<StatsFactory>empty(),
      Option.<String>empty(),
      List$.MODULE$.<Regex>empty(),
      Map$.MODULE$.<String, CustomHttpHandler>empty(),
      List.<Duration>fromArray(defaultLatchIntervals));
  RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
  AdminHttpService service = adminServiceFactory.apply(runtimeEnvironment);
  for (Map.Entry<String, CustomHttpHandler> entry : this.mCustomHttpHandlerMap.entrySet()) {
    service.httpServer().createContext(entry.getKey(), entry.getValue());
  }
}
 
Example 4
Source File: OstrichAdminService.java    From secor with Apache License 2.0 6 votes vote down vote up
public void start() {
    Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
    @SuppressWarnings("deprecation")
    AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
        this.mPort,
        20,
        List$.MODULE$.<StatsFactory>empty(),
        Option.<String>empty(),
        List$.MODULE$.<Regex>empty(),
        Map$.MODULE$.<String, CustomHttpHandler>empty(),
        JavaConversions
            .asScalaBuffer(Arrays.asList(defaultLatchIntervals)).toList()
    );
    RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
    adminServiceFactory.apply(runtimeEnvironment);
    try {
        Properties properties = new Properties();
        properties.load(this.getClass().getResource("build.properties").openStream());
        String buildRevision = properties.getProperty("build_revision", "unknown");
        LOG.info("build.properties build_revision: {}",
                 properties.getProperty("build_revision", "unknown"));
        StatsUtil.setLabel("secor.build_revision", buildRevision);
    } catch (Throwable t) {
        LOG.error("Failed to load properties from build.properties", t);
    }
}
 
Example 5
Source File: OstrichAdminService.java    From singer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("restriction")
public void start() {
  try {
    Properties properties = new Properties();
    properties.load(this.getClass().getResource("build.properties").openStream());
    LOG.info("build.properties build_revision: {}",
        properties.getProperty("build_revision", "unknown"));
  } catch (Throwable t) {
    LOG.warn("Failed to load properties from build.properties");
  }
  Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
  Iterator<Duration> durationIterator = Arrays.asList(defaultLatchIntervals).iterator();

  AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
          this.port,
          20,
          List$.MODULE$.<StatsFactory>empty(),
          Option.<String>empty(),
          List$.MODULE$.<Regex>empty(),
          Map$.MODULE$.<String, CustomHttpHandler>empty(),
          JavaConversions.asScalaIterator(durationIterator).toList());

  RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
  AdminHttpService service = adminServiceFactory.apply(runtimeEnvironment);
  for (Map.Entry<String, CustomHttpHandler> entry : this.customHttpHandlerMap.entrySet()) {
    service.httpServer().createContext(entry.getKey(), entry.getValue());
  }
}
 
Example 6
Source File: LindenClient.java    From linden with Apache License 2.0 4 votes vote down vote up
public LindenClient(String clusterUrl, int timeout, final boolean roundRobin) {
  this.timeout = timeout;
  this.duration = Duration.apply(timeout, TimeUnit.MILLISECONDS);
  LindenZKPathManager zkPathManager = new LindenZKPathManager(clusterUrl);
  zkClient = ZKClientFactory.getClient(zkPathManager.getZK());
  nodesPath = zkPathManager.getAllNodesPath();
  List<String> children = zkClient.getChildren(nodesPath);

  zkListener = new LindenZKListener(nodesPath, children) {
    @Override
    public void onChildChange(String parent, List<String> children, List<String> newAdded, List<String> deleted) {
      if (children == null || children.isEmpty()) {
        return;
      }

      if (!roundRobin) {
        Collections.sort(children);
        String firstNode = children.get(0);
        LindenService.ServiceIface leader = clients.get(firstNode);
        if (leader == null) {
          leader = buildClient(parent, firstNode);
          clients.put(firstNode, leader);
          LOGGER.info("Linden client [{}] is selected as leader.", parent);
        }
        clientIface = new SingleClient(leader);
        return;
      }

      Map<String, LindenService.ServiceIface> tmpClients = new ConcurrentHashMap<>();
      for (String child : children) {
        if (!clients.containsKey(child)) {
          clients.put(child, buildClient(parent, child));
          LOGGER.info("Linden client [{}] joined to the cluster.", parent);
        }
        tmpClients.put(child, clients.get(child));
      }
      for (String delete : deleted) {
        clients.remove(delete);
      }
      clientIface = new RoundRobinClient(tmpClients.values());
    }
  };
  zkClient.subscribeChildChanges(nodesPath, zkListener);
}
 
Example 7
Source File: LindenClient.java    From linden with Apache License 2.0 4 votes vote down vote up
public LindenClient(String host, int port, int timeout) {
  this.timeout = timeout;
  this.duration = Duration.apply(timeout, TimeUnit.MILLISECONDS);
  LindenService.ServiceIface iface = Thrift.newIface(String.format("%s:%d", host, port), LindenService.ServiceIface.class);
  clientIface = new SingleClient(iface);
}
 
Example 8
Source File: ClusterAnnouncer.java    From linden with Apache License 2.0 4 votes vote down vote up
public ClusterAnnouncer(LindenConfig lindenConf) {
  this.lindenConf = lindenConf;
  zkPathManager = new LindenZKPathManager(lindenConf.getClusterUrl());
  ZkClientFactory factory = new ZkClientFactory(Duration.apply(30, TimeUnit.SECONDS));
  announcer = new ZkAnnouncer(factory);
}