use of org.openecard.ifd.event.IfdEventManager 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());
}
}
Aggregations