public void addPingStartPlugin() { String msg = internal.createPingStartPluginEncodedMessage(); synchronized (lockOperations) { operations.add(new Tuple<String, String>("addEncodedMessage", msg)); } job.schedule(SCHEDULE_TIME); }
/** * Actually executes the commands. * * <p>If send is passed, send command are handled, otherwise they're ignored. */ private void consumeAllCommands(final boolean send) { ArrayList<Object> local; synchronized (lockOperations) { local = new ArrayList<Object>(operations); operations.clear(); } synchronized (lockExecuteCommands) { boolean containsSend = local.contains("send"); if (containsSend) { for (Iterator<Object> it = local.iterator(); it.hasNext(); ) { if ("send".equals(it.next())) { it.remove(); // remove any send } } } // make all pings before a send. for (Object cmd : local) { if (cmd instanceof Tuple) { Tuple tuple = (Tuple) cmd; if ("addEncodedMessage".equals(tuple.o1)) { internal.addEncodedMessage((String) tuple.o2); continue; } } // if it got here, the command wasn't handled. Log.log("Invalid command: " + cmd); } if (send) { // make the send. if (containsSend) { internal.send(); } } } }
/** * Yes, this is the exception that's not asynchronous! Note that sends won't execute at this time. * So, commands will only be added at this time without any actual send. */ public void stop() { consumeAllCommands(false); internal.stop(); }