@Test public void testConnectOnContactStatusChanged() throws Exception { SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class); SimplexPlugin simplexPlugin1 = context.mock(SimplexPlugin.class, "simplexPlugin1"); TransportId simplexId1 = getTransportId(); List<SimplexPlugin> simplexPlugins = asList(simplexPlugin, simplexPlugin1); TransportConnectionWriter simplexWriter = context.mock(TransportConnectionWriter.class); DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class); TransportId duplexId = getTransportId(); DuplexPlugin duplexPlugin1 = context.mock(DuplexPlugin.class, "duplexPlugin1"); List<DuplexPlugin> duplexPlugins = asList(duplexPlugin, duplexPlugin1); DuplexTransportConnection duplexConnection = context.mock(DuplexTransportConnection.class); context.checking(new Expectations() {{ oneOf(pluginManager).getSimplexPlugins(); will(returnValue(simplexPlugins)); oneOf(simplexPlugin).shouldPoll(); will(returnValue(false)); oneOf(simplexPlugin1).shouldPoll(); will(returnValue(true)); oneOf(simplexPlugin1).getId(); will(returnValue(simplexId1)); oneOf(connectionRegistry).isConnected(contactId, simplexId1); will(returnValue(false)); oneOf(transportPropertyManager).getRemoteProperties(contactId, simplexId1); will(returnValue(properties)); oneOf(simplexPlugin1).createWriter(properties); will(returnValue(simplexWriter)); oneOf(connectionManager).manageOutgoingConnection(contactId, simplexId1, simplexWriter); oneOf(pluginManager).getDuplexPlugins(); will(returnValue(duplexPlugins)); oneOf(duplexPlugin).shouldPoll(); will(returnValue(true)); oneOf(duplexPlugin).getId(); will(returnValue(duplexId)); oneOf(connectionRegistry).isConnected(contactId, duplexId); will(returnValue(false)); oneOf(transportPropertyManager).getRemoteProperties(contactId, duplexId); will(returnValue(properties)); oneOf(duplexPlugin).createConnection(properties); will(returnValue(duplexConnection)); oneOf(connectionManager).manageOutgoingConnection(contactId, duplexId, duplexConnection); oneOf(duplexPlugin1).shouldPoll(); will(returnValue(false)); }}); Poller p = new Poller(ioExecutor, scheduler, connectionManager, connectionRegistry, pluginManager, transportPropertyManager, random, clock); p.eventOccurred(new ContactStatusChangedEvent(contactId, true)); }
@Override public void eventOccurred(Event e) { if (e instanceof ContactStatusChangedEvent) { ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; if (c.isActive()) { connectToContact(c.getContactId()); } } else if (e instanceof ConnectionClosedEvent) { ConnectionClosedEvent c = (ConnectionClosedEvent) e; reschedule(c.getTransportId()); if (!c.isIncoming()) { connectToContact(c.getContactId(), c.getTransportId()); } } else if (e instanceof ConnectionOpenedEvent) { ConnectionOpenedEvent c = (ConnectionOpenedEvent) e; reschedule(c.getTransportId()); } else if (e instanceof TransportEnabledEvent) { TransportEnabledEvent t = (TransportEnabledEvent) e; pollNow(t.getTransportId()); } else if (e instanceof TransportDisabledEvent) { TransportDisabledEvent t = (TransportDisabledEvent) e; cancel(t.getTransportId()); } }
Poller implements EventListener { @Override public void eventOccurred(Event e) { if (e instanceof ContactStatusChangedEvent) { ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; if (c.isActive()) { connectToContact(c.getContactId()); } } else if (e instanceof ConnectionClosedEvent) { ConnectionClosedEvent c = (ConnectionClosedEvent) e; reschedule(c.getTransportId()); if (!c.isIncoming()) { connectToContact(c.getContactId(), c.getTransportId()); } } else if (e instanceof ConnectionOpenedEvent) { ConnectionOpenedEvent c = (ConnectionOpenedEvent) e; reschedule(c.getTransportId()); } else if (e instanceof TransportEnabledEvent) { TransportEnabledEvent t = (TransportEnabledEvent) e; pollNow(t.getTransportId()); } else if (e instanceof TransportDisabledEvent) { TransportDisabledEvent t = (TransportDisabledEvent) e; cancel(t.getTransportId()); } } }
Poller implements EventListener { @Override public void eventOccurred(Event e) { if (e instanceof ContactStatusChangedEvent) { ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; if (c.isActive()) { connectToContact(c.getContactId()); } } else if (e instanceof ConnectionClosedEvent) { ConnectionClosedEvent c = (ConnectionClosedEvent) e; reschedule(c.getTransportId()); if (!c.isIncoming()) { connectToContact(c.getContactId(), c.getTransportId()); } } else if (e instanceof ConnectionOpenedEvent) { ConnectionOpenedEvent c = (ConnectionOpenedEvent) e; reschedule(c.getTransportId()); } else if (e instanceof TransportEnabledEvent) { TransportEnabledEvent t = (TransportEnabledEvent) e; pollNow(t.getTransportId()); } else if (e instanceof TransportDisabledEvent) { TransportDisabledEvent t = (TransportDisabledEvent) e; cancel(t.getTransportId()); } } Poller(@IoExecutor Executor ioExecutor,
			@Scheduler ScheduledExecutorService scheduler,
			ConnectionManager connectionManager,
			ConnectionRegistry connectionRegistry, PluginManager pluginManager,
			TransportPropertyManager transportPropertyManager,
			SecureRandom random, Clock clock); }
Poller implements EventListener { @Override public void eventOccurred(Event e) { if (e instanceof ContactStatusChangedEvent) { ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; if (c.isActive()) { connectToContact(c.getContactId()); } } else if (e instanceof ConnectionClosedEvent) { ConnectionClosedEvent c = (ConnectionClosedEvent) e; reschedule(c.getTransportId()); if (!c.isIncoming()) { connectToContact(c.getContactId(), c.getTransportId()); } } else if (e instanceof ConnectionOpenedEvent) { ConnectionOpenedEvent c = (ConnectionOpenedEvent) e; reschedule(c.getTransportId()); } else if (e instanceof TransportEnabledEvent) { TransportEnabledEvent t = (TransportEnabledEvent) e; pollNow(t.getTransportId()); } else if (e instanceof TransportDisabledEvent) { TransportDisabledEvent t = (TransportDisabledEvent) e; cancel(t.getTransportId()); } } Poller(@IoExecutor Executor ioExecutor,
			@Scheduler ScheduledExecutorService scheduler,
			ConnectionManager connectionManager,
			ConnectionRegistry connectionRegistry, PluginManager pluginManager,
			TransportPropertyManager transportPropertyManager,
			SecureRandom random, Clock clock); @Override void eventOccurred(Event e); }
Poller implements EventListener { @Override public void eventOccurred(Event e) { if (e instanceof ContactStatusChangedEvent) { ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; if (c.isActive()) { connectToContact(c.getContactId()); } } else if (e instanceof ConnectionClosedEvent) { ConnectionClosedEvent c = (ConnectionClosedEvent) e; reschedule(c.getTransportId()); if (!c.isIncoming()) { connectToContact(c.getContactId(), c.getTransportId()); } } else if (e instanceof ConnectionOpenedEvent) { ConnectionOpenedEvent c = (ConnectionOpenedEvent) e; reschedule(c.getTransportId()); } else if (e instanceof TransportEnabledEvent) { TransportEnabledEvent t = (TransportEnabledEvent) e; pollNow(t.getTransportId()); } else if (e instanceof TransportDisabledEvent) { TransportDisabledEvent t = (TransportDisabledEvent) e; cancel(t.getTransportId()); } } Poller(@IoExecutor Executor ioExecutor,
			@Scheduler ScheduledExecutorService scheduler,
			ConnectionManager connectionManager,
			ConnectionRegistry connectionRegistry, PluginManager pluginManager,
			TransportPropertyManager transportPropertyManager,
			SecureRandom random, Clock clock); @Override void eventOccurred(Event e);  }