use of org.openecard.ifd.scio.wrapper.ChannelManager in project open-ecard by ecsec.
the class IFD method establishContext.
@Override
public synchronized EstablishContextResponse establishContext(EstablishContext parameters) {
EstablishContextResponse response;
try {
// on first call, create a new unique handle
if (ctxHandle == null) {
// scwrapper = new SCWrapper();
cm = new ChannelManager();
ctxHandle = ChannelManager.createCtxHandle();
env.addIFDCtx(ctxHandle);
numClients = new AtomicInteger(1);
// TODO: add custom ThreadFactory to control the thread name
threadPool = Executors.newCachedThreadPool(new ThreadFactory() {
private final AtomicInteger num = new AtomicInteger(0);
private final ThreadGroup group = new ThreadGroup("IFD Wait");
@Override
public Thread newThread(Runnable r) {
String name = String.format("SCIO Watcher %d", num.getAndIncrement());
Thread t = new Thread(group, r, name);
t.setDaemon(false);
return t;
}
});
asyncWaitThreads = new ConcurrentSkipListMap<>();
evManager = new IfdEventManager(env, cm, ctxHandle);
evManager.initialize();
} else {
// on second or further calls, increment usage counter
numClients.incrementAndGet();
}
// prepare response
response = WSHelper.makeResponse(EstablishContextResponse.class, WSHelper.makeResultOK());
response.setContextHandle(ctxHandle);
return response;
} catch (IFDException ex) {
LOG.warn(ex.getMessage(), ex);
return WSHelper.makeResponse(EstablishContextResponse.class, ex.getResult());
}
}
use of org.openecard.ifd.scio.wrapper.ChannelManager in project open-ecard by ecsec.
the class ManagerTest method runManager.
@Test(enabled = false)
public void runManager() throws InterruptedException, IFDException {
IFD ifd = new IFD();
EstablishContext ctx = new EstablishContext();
EstablishContextResponse ctxR = ifd.establishContext(ctx);
Environment env = new ClientEnv();
env.setIFD(ifd);
IfdEventManager evt = new IfdEventManager(env, new ChannelManager(), ctxR.getContextHandle());
evt.initialize();
Thread.sleep(1000);
// evt.terminate();
Thread.sleep(1000000);
}
Aggregations