private void connect (int slot) { ISOChannel c = channels[slot]; if (c != null && !c.isConnected()) { try { c.connect (); sp.put (ready, new Date()); } catch (IOException e) { getLog().warn ("check-connection(" + slot + ") " + c.toString(), e.getMessage ()); } } } private void disconnect (ISOChannel channel) {
public synchronized void connect () throws IOException { current = null; LogEvent evt = new LogEvent (this, "connect"); evt.addMessage ("pool-size=" + Integer.toString (pool.size())); for (int i=0; i<pool.size(); i++) { try { evt.addMessage ("pool-" + Integer.toString (i)); ISOChannel c = (ISOChannel) pool.get (i); c.connect (); if (c.isConnected()) { current = c; usable = true; break; } } catch (IOException e) { evt.addMessage (e); } } if (current == null) evt.addMessage ("connect failed"); Logger.log (evt); if (current == null) { throw new IOException ("unable to connect"); } } public synchronized void disconnect () throws IOException {
if (firstTime) { firstTime = !firstTime; channel.connect();
protected void checkConnection () { try { while (!channel.isConnected ()) { while (sp.inp (ready) != null) ; channel.connect (); if (!channel.isConnected ()) ISOUtil.sleep (10000); } sp.out (ready, new Object ()); } catch (IOException e) { Logger.log ( new LogEvent ( ISOChannelAdaptor.this, "check-connection", e ) ); ISOUtil.sleep (10000); } } protected void disconnect () {
@Test public void stopCanWaitForWorkersEvenWhenSenderBlockedTryingToConnect() throws Exception { // Think a link where the other ends plays the client role. Eg a BaseChannel with a serverSocket. // So connect() calls socket.accept(). If no client connects accept() blocks forever. // Ensures disconnect() is called on stop() regardless of channel.isConnected() return value. ISOChannel channel = mock(ISOChannel.class); ThreadTrap trap = new ThreadTrap(SENDER_THREAD_NAME); when(channel.isConnected()).thenReturn(false); trap.catchVictim().when(channel).connect(); trap.release().when(channel).disconnect(); channelAdaptor = configureAndStart(new ChannelAdaptorWithoutQ2(channel)); waitForSenderAndReceiverToStart(); assertThat("Sender did not call connect()", trap.catchesVictim(), is(true)); assertCallToStopCompletes(1); }
protected void checkConnection () { while (running() && sp.rdp (reconnect) != null) { ISOUtil.sleep(1000); } while (running() && !channel.isConnected ()) { SpaceUtil.wipe(sp, ready); try { channel.connect (); } catch (IOException ignored) { // channel.connect already logs - no need for more warnings } if (!channel.isConnected ()) ISOUtil.sleep (delay); else connects++; } if (running() && sp.rdp (ready) == null) sp.out (ready, new Date()); } protected void disconnect () {
bc.setLogger(null, null); channel.connect(); res = true;
channel.connect();