Search in sources :

Example 1 with ChannelManager

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());
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ChannelManager(org.openecard.ifd.scio.wrapper.ChannelManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) IfdEventManager(org.openecard.ifd.event.IfdEventManager)

Example 2 with ChannelManager

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);
}
Also used : ClientEnv(org.openecard.common.ClientEnv) ChannelManager(org.openecard.ifd.scio.wrapper.ChannelManager) IFD(org.openecard.ifd.scio.IFD) Environment(org.openecard.common.interfaces.Environment) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) Test(org.testng.annotations.Test)

Aggregations

EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)2 ChannelManager (org.openecard.ifd.scio.wrapper.ChannelManager)2 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ClientEnv (org.openecard.common.ClientEnv)1 Environment (org.openecard.common.interfaces.Environment)1 IfdEventManager (org.openecard.ifd.event.IfdEventManager)1 IFD (org.openecard.ifd.scio.IFD)1 Test (org.testng.annotations.Test)1