List of usage examples for com.google.common.util.concurrent Service getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:co.runrightfast.core.utils.ServiceUtils.java
/** * Logs a warning every 10 seconds, waiting for the service to start * * @param service Service//from w w w.java 2 s . c o m */ static void awaitRunning(@NonNull final Service service) { while (true) { try { service.awaitRunning(10, TimeUnit.SECONDS); return; } catch (final TimeoutException ex) { LOG.logp(WARNING, ServiceUtils.class.getName(), "awaitTerminated", "Wating for service to start : {0}", service.getClass().getName()); } } }
From source file:co.runrightfast.core.utils.ServiceUtils.java
/** * Logs a warning every 10 seconds, waiting for the service to stop * * @param service Service/*w w w. j a v a 2 s . c om*/ */ static void awaitTerminated(@NonNull final Service service) { while (true) { try { service.awaitTerminated(10, TimeUnit.SECONDS); return; } catch (final TimeoutException ex) { LOG.logp(WARNING, ServiceUtils.class.getName(), "awaitTerminated", "Wating for service to terminate : {0}", service.getClass().getName()); } } }
From source file:com.technostar98.tcbot.bot.BotManager.java
public static void start() { synchronized (lock) { List<Service> services = Lists.newLinkedList(); for (final Map.Entry<String, IRCBot> e : bots.entrySet()) { Service s = new AbstractExecutionThreadService() { IRCBot bot = e.getValue(); String server = e.getKey(); @Override/*from w w w . j a v a2 s. c o m*/ protected void run() throws Exception { Logger.info("Bot for %s server starting up.", server); bot.getBot().startBot(); } @Override protected void startUp() throws Exception { super.startUp(); } @Override protected void shutDown() throws Exception { super.shutDown(); /*System.out.println("Shutting down."); bot.getBot().stopBotReconnect(); bot.getBot().sendIRC().quitServer("Adios"); getBotOutputPipe(server).messengerPipeline.setOutputEnabled(false); getBotOutputPipe(server).closeListener(); try { Thread.sleep(50L); } catch (InterruptedException e1) { e1.printStackTrace(); } bot.getBot().getInputParser().close(); bots.remove(server);*/ } @Override protected void triggerShutdown() { super.triggerShutdown(); Logger.info("Bot for server %s is shutting down. Closing all tied resources.", server); try { shutDown(); } catch (Exception e1) { e1.printStackTrace(); } } }; services.add(s); } manager = new ServiceManager(services); manager.addListener(new ServiceManager.Listener() { @Override public void healthy() { super.healthy(); Logger.info("All bot instances started correctly."); } @Override public void stopped() { super.stopped(); Logger.info("All bots shutdown."); } @Override public void failure(Service service) { super.failure(service); try { IRCBot bot = (IRCBot) service.getClass().getDeclaredField("bot").get(service); Logger.info("Bot for server %s has failed to start.", bot.getServerConfiguration().getServerName()); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }); manager.startAsync(); dataManager = new Thread(() -> { while (bots.size() > 0) { try { Thread.sleep(600000); } catch (InterruptedException e) { //ignore } bots.keySet().forEach( s -> getBotOutputPipe(s).getChannelManagers().forEach(c -> c.saveChannelData())); } }); dataManager.start(); } }
From source file:co.runrightfast.commons.utils.ServiceUtils.java
/** * Logs a warning every 10 seconds, waiting for the service to start * * @param service Service/*www. j a v a2s . c o m*/ */ public static void awaitRunning(@NonNull final Service service) { for (int i = 1; true; i++) { try { service.awaitRunning(10, TimeUnit.SECONDS); return; } catch (final TimeoutException ex) { final int elapsedTimeSeconds = i * 10; log.warn(String.format("Wating for service to start : %s : %d seconds", service.getClass().getName(), elapsedTimeSeconds), new ApplicationException(MAJOR, ex)); } } }
From source file:co.runrightfast.commons.utils.ServiceUtils.java
public static void stopAsync(final Service service) { if (service != null) { switch (service.state()) { case STARTING: case RUNNING: service.stopAsync();//from w ww. j a va 2 s . c om return; case STOPPING: return; case NEW: case FAILED: case TERMINATED: log.debug("Service ({}) is not running: {}", service.getClass().getName(), service.state()); } } }
From source file:co.runrightfast.commons.utils.ServiceUtils.java
/** * Logs a warning every 10 seconds, waiting for the service to stop * * @param service Service/* ww w. ja v a 2s.c o m*/ */ public static void awaitTerminated(@NonNull final Service service) { for (int i = 1; true; i++) { try { service.awaitTerminated(10, TimeUnit.SECONDS); return; } catch (final TimeoutException ex) { final int elapsedTimeSeconds = i * 10; log.warn( String.format("Wating for service to terminate : %s : %d seconds", service.getClass().getName(), elapsedTimeSeconds), new ApplicationException(MAJOR, ex)); } } }
From source file:co.runrightfast.core.utils.ServiceUtils.java
static void stopAsync(final Service service) { if (service != null) { switch (service.state()) { case STARTING: case RUNNING: service.stopAsync();/*from ww w . j a va 2 s .co m*/ return; case STOPPING: return; case NEW: case FAILED: case TERMINATED: LOG.logp(FINE, ServiceUtils.class.getName(), "stop", () -> String .format("Service (%s) is not running: %s", service.getClass().getName(), service.state())); } } }
From source file:co.runrightfast.commons.utils.ServiceUtils.java
/** * * @param service if null, then do nothing *///from w ww. ja v a2 s . c o m public static void stop(final Service service) { if (service != null) { switch (service.state()) { case STARTING: case RUNNING: service.stopAsync(); awaitTerminated(service); return; case STOPPING: awaitTerminated(service); return; case NEW: case FAILED: case TERMINATED: log.debug("Service ({}) is not running: {}", service.getClass().getName(), service.state()); } } }
From source file:co.runrightfast.core.utils.ServiceUtils.java
/** * * @param service if null, then do nothing *///from www . j a v a 2 s . c o m static void stop(final Service service) { if (service != null) { switch (service.state()) { case STARTING: case RUNNING: service.stopAsync(); awaitTerminated(service); return; case STOPPING: awaitTerminated(service); return; case NEW: case FAILED: case TERMINATED: LOG.logp(FINE, ServiceUtils.class.getName(), "stop", () -> String .format("Service (%s) is not running: %s", service.getClass().getName(), service.state())); } } }
From source file:com.brighttag.agathon.service.impl.ServiceRegistry.java
private String serviceName(Service service) { return service.getClass().getSimpleName(); }