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) {
private void shutdownChannels () { Iterator iter = channels.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); WeakReference ref = (WeakReference) entry.getValue(); ISOChannel c = (ISOChannel) ref.get (); if (c != null) { try { c.disconnect (); fireEvent(new ISOServerClientDisconnectEvent(this, c)); } catch (IOException e) { Logger.log (new LogEvent (this, "shutdown", e)); } } } } private void purgeChannels () {
public ISOMsg receive() throws IOException, ISOException { return getCurrent().receive (); } public void send (ISOMsg m) throws IOException, ISOException {
/** * ISOMUXs usually calls connect() on the underlying ISOChannel<br> * You can prevent this behaveour by passing a false value. * @param connect false to prevent connection (default true) */ public void setConnect (boolean connect) { this.doConnect = connect; if (!connect && isConnected()) { channel.setUsable(false); try { channel.disconnect(); } catch (IOException e) { Logger.log (new LogEvent(this, "set-connect", e)); } synchronized(this) { this.notify(); } } } /**
if (getName() != null) channel.setName(getName() + id); channel.connect(); if (channel.isConnected()) channel.send(req); ISOMsg rsp = channel.receive(); channel.disconnect(); if (handBack != null) channel.disconnect();
if (handbackFields.length > 0) handBack = (ISOMsg) m.clone (handbackFields); for (int i=0; !channel.isConnected() && i<maxConnectAttempts; i++) channel.reconnect(); if (!channel.isConnected()) ISOUtil.sleep (1000L); if (channel.isConnected()) { channel.send (m); m = channel.receive(); channel.disconnect(); if (handBack != null) m.merge (handBack); } finally { try { channel.disconnect(); } catch (Exception e) { getLog().warn ("channel-worker-"+id, e.getMessage ());
while (!terminate || !txQueue.isEmpty()) { try { if (channel.isConnected()) { doTransmit(); if (firstTime) { firstTime = !firstTime; channel.connect(); channel.reconnect(); channel.isConnected() && txQueue.size() == 0) channel.disconnect(); } catch (IOException e) { }
bc.setLogger(null, null); channel.connect(); res = true; if (channel != null && channel.isConnected()) channel.disconnect(); NameRegistrar.unregister("channel."+channel.getName());
@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); }
private int getConnectedCount() { int connected = 0; for (ISOChannel c : channels) { if (c != null && c.isConnected()) { connected++; } } return connected; } }
if (i++ % 250 == 1) Logger.log (new LogEvent (this, "mux", parent)); if (channel.isConnected()) { try { ISOMsg d = channel.receive(); cnt[RX]++; String k = getKey(d); channel.setUsable(false); if (!(e instanceof EOFException)) Logger.log (new LogEvent (this, "muxreceiver", e));
@Test public void stopCanWaitForWorkersEvenWhenOutgoingChannelNeverConnects() throws Exception { ISOChannel channel = mock(ISOChannel.class); when(channel.isConnected()).thenReturn(false); when(channel.receive()).thenThrow(new ISOException("unconnected ISOChannel")); // repeat test to ensure clean up occurs after stop for (int i = 0; i < 10; i++) { channelAdaptor = configureAndStart(new ChannelAdaptorWithoutQ2(channel)); waitForSenderAndReceiverToStart(); assertCallToStopCompletes(i); } }
throw new ISOException("Server has no active connections"); if (!c.isConnected()) { throw new ISOException("Client disconnected"); c.send(m); throw new ISOException("Server has no active connections"); if (!c.isConnected()) { throw new ISOException("Client disconnected"); c.send(m); } catch (Exception e) { getLog().warn("notify", e); throw new ISOException("Server has no active connections"); if (!c.isConnected()) { throw new ISOException("Client disconnected"); c.send(m); } catch (Exception e) { getLog().warn("notify", e);
@Override public synchronized void send(ISOMsg m) throws IOException, ISOException { response.add(m); channel.send(m); notifyAll(); }
public static void configureFilter(FilterISOMsg filter, ISOServer server) { ISOChannel c = server.clientSideChannel != null ? server.clientSideChannel : server.getISOChannel(":last"); c = (c != null ? (ISOChannel) c.clone() : null); filter.configure((BaseChannel) c, server.listeners); if (filter.getPackager() == null) { filter.setPackager(server.clientPackager); } filter.setPort(server.getPort()); }
private ISOChannel newChannel (Element e, QFactory f) throws ConfigurationException { String channelName = e.getAttributeValue ("class"); if (channelName == null) throw new ConfigurationException ("class attribute missing from channel element."); String packagerName = e.getAttributeValue ("packager"); ISOChannel channel = (ISOChannel) f.newInstance (channelName); ISOPackager packager; if (packagerName != null) { packager = (ISOPackager) f.newInstance (packagerName); channel.setPackager (packager); f.setConfiguration (packager, e); } QFactory.invoke (channel, "setHeader", e.getAttributeValue ("header")); f.setLogger (channel, e); f.setConfiguration (channel, e); if (channel instanceof FilteredChannel) { addFilters ((FilteredChannel) channel, e, f); } if (getName () != null) channel.setName (getName ()+id); return channel; }
@Override public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) { if (channelNameField != null) m.set(channelNameField, channel.getName()); if (socketInfoField != null && channel instanceof BaseChannel) { Socket socket = ((BaseChannel) channel).getSocket(); InetSocketAddress remoteAddr = (InetSocketAddress) socket.getRemoteSocketAddress(); InetSocketAddress localAddr = (InetSocketAddress) socket.getLocalSocketAddress(); StringBuilder sb = new StringBuilder(); if (socketInfoField.equals(channelNameField)) { sb.append(channel.getName()); sb.append(' '); } sb.append(localAddr.getAddress().getHostAddress()); sb.append(':'); sb.append(Integer.toString (localAddr.getPort())); sb.append(' '); sb.append(remoteAddr.getAddress().getHostAddress()); sb.append(':'); sb.append(Integer.toString (remoteAddr.getPort())); m.set (socketInfoField, sb.toString()); } return m; } }
public boolean isConnected() { return channel.isConnected(); } public void setLogger (Logger logger, String realm) {
while (running()) { try { if (!channel.isConnected()) { connect(slot); if (!channel.isConnected()) { ISOUtil.sleep(delay); continue; ISOMsg m = channel.receive (); rx++; lastTxn = System.currentTimeMillis();
Object o = sp.in (in, delay); if (o instanceof ISOMsg) { channel.send ((ISOMsg) o); tx++; else if (keepAlive && channel.isConnected() && channel instanceof BaseChannel) { ((BaseChannel)channel).sendKeepAlive();