use of org.jpos.iso.ISOChannel in project jPOS by jpos.
the class MacroFilterTest method testFilter.
@Test
public void testFilter() throws Throwable {
MacroFilter macroFilter = new MacroFilter();
ISOChannel channel = new GZIPChannel(new X92GenericPackager());
LogEvent evt = new LogEvent("testMacroFilterTag", "\u0000\u0000");
when(m.getMaxField()).thenReturn(0);
ISOMsg result = macroFilter.filter(channel, m, evt);
assertSame("result", m, result);
verify(m).hasField(0);
}
use of org.jpos.iso.ISOChannel in project jPOS by jpos.
the class ISOMeterFactory method create.
public JComponent create(UI ui, Element e) {
ISOChannelPanel icp = null;
try {
Object obj = NameRegistrar.get(e.getAttributeValue("idref"));
if (obj instanceof ISOChannel) {
icp = new ISOChannelPanel((ISOChannel) obj, e.getText());
} else if (obj instanceof Observable) {
icp = new ISOChannelPanel(e.getText());
((Observable) obj).addObserver(icp);
}
ISOMeter meter = icp.getISOMeter();
if ("false".equals(e.getAttributeValue("scroll")))
meter.setScroll(false);
String protect = e.getAttributeValue("protect");
if (protect != null)
icp.setProtectFields(ISOUtil.toIntArray(protect));
String wipe = e.getAttributeValue("wipe");
if (wipe != null)
icp.setWipeFields(ISOUtil.toIntArray(wipe));
String refresh = e.getAttributeValue("refresh");
if (refresh != null)
meter.setRefresh(Integer.parseInt(refresh));
} catch (Exception ex) {
ex.printStackTrace();
return new JLabel(ex.getMessage());
}
return icp;
}
use of org.jpos.iso.ISOChannel in project jPOS by jpos.
the class ChannelPool method connect.
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");
}
}
use of org.jpos.iso.ISOChannel in project jPOS by jpos.
the class ChannelPool method disconnect.
public synchronized void disconnect() throws IOException {
current = null;
LogEvent evt = new LogEvent(this, "disconnect");
for (Object aPool : pool) {
try {
ISOChannel c = (ISOChannel) aPool;
c.disconnect();
} catch (IOException e) {
evt.addMessage(e);
}
}
Logger.log(evt);
}
use of org.jpos.iso.ISOChannel in project jPOS by jpos.
the class ChannelAdaptorTest method stopCanWaitForWorkersEvenWhenSenderBlockedTryingToConnect.
@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);
}
Aggregations