/** * Constructor. * * @param connection the XMPP connection */ private InBandBytestreamManager(XMPPConnection connection) { super(connection); // register bytestream open packet listener this.initiationListener = new InitiationListener(this); connection.registerIQRequestHandler(initiationListener); // register bytestream data packet listener this.dataListener = new DataListener(this); connection.registerIQRequestHandler(dataListener); // register bytestream close packet listener this.closeListener = new CloseListener(this); connection.registerIQRequestHandler(closeListener); }
/** * If a close request to an unknown session is received it should be replied * with an <item-not-found/> error. * * @throws Exception should not happen */ @Test public void shouldReplyErrorIfSessionIsUnknown() throws Exception { // mock connection XMPPConnection connection = mock(XMPPConnection.class); // initialize InBandBytestreamManager to get the CloseListener InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); // get the CloseListener from InBandByteStreamManager CloseListener closeListener = Whitebox.getInternalState(byteStreamManager, CloseListener.class); Close close = new Close("unknownSessionId"); close.setFrom(initiatorJID); close.setTo(targetJID); closeListener.handleIQRequest(close); // wait because packet is processed in an extra thread Thread.sleep(200); // capture reply to the In-Band Bytestream close request ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.item_not_found, argument.getValue().getError().getCondition()); }
/** * Constructor. * * @param connection the XMPP connection */ private InBandBytestreamManager(Connection connection) { this.connection = connection; // register bytestream open packet listener this.initiationListener = new InitiationListener(this); this.connection.addPacketListener(this.initiationListener, this.initiationListener.getFilter()); // register bytestream data packet listener this.dataListener = new DataListener(this); this.connection.addPacketListener(this.dataListener, this.dataListener.getFilter()); // register bytestream close packet listener this.closeListener = new CloseListener(this); this.connection.addPacketListener(this.closeListener, this.closeListener.getFilter()); }
/** * Constructor. * * @param connection the XMPP connection */ private InBandBytestreamManager(Connection connection) { this.connection = connection; // register bytestream open packet listener this.initiationListener = new InitiationListener(this); this.connection.addPacketListener(this.initiationListener, this.initiationListener.getFilter()); // register bytestream data packet listener this.dataListener = new DataListener(this); this.connection.addPacketListener(this.dataListener, this.dataListener.getFilter()); // register bytestream close packet listener this.closeListener = new CloseListener(this); this.connection.addPacketListener(this.closeListener, this.closeListener.getFilter()); }
/** * Constructor. * * @param connection the XMPP connection */ private InBandBytestreamManager(Connection connection) { this.connection = connection; // register bytestream open packet listener this.initiationListener = new InitiationListener(this); this.connection.addPacketListener(this.initiationListener, this.initiationListener.getFilter()); // register bytestream data packet listener this.dataListener = new DataListener(this); this.connection.addPacketListener(this.dataListener, this.dataListener.getFilter()); // register bytestream close packet listener this.closeListener = new CloseListener(this); this.connection.addPacketListener(this.closeListener, this.closeListener.getFilter()); }
public class YourActivity extends Activity{ private class CloseLisntener extends BroadcastReceiver{ onReceive(Contetxt context, Intent intent){ YourActivity.this.finish(); } } private CloseListener closeListener; protected void onCreate(Intent icicle){ closeListener = new CloseListener(); // other on create stuff } protected void onResume(){ registerReceiver(closeListener, /* Your intent filter goes here */); } protected void onPause(){ unregisterReceiver(closeListener); } }
public class VaadintestsApplication extends Application { @Override public void init() { final Window rootWindow = new Window(); setMainWindow(rootWindow); rootWindow.addListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { setUser(null); } }); } }
createProjectWindow.setResizable(false); createProjectWindow.setModal(true); createProjectWindow.addCloseListener(new CloseListener(){