Search in sources :

Example 1 with StatusChange

use of org.openecard.ws.schema.StatusChange in project open-ecard by ecsec.

the class WaitForChangeAction method execute.

@Override
public BindingResult execute(RequestBody body, Map<String, String> parameters, Headers headers, List<Attachment> attachments) {
    BindingResult response;
    try {
        WaitForChangeRequest statusRequest = WaitForChangeRequest.convert(parameters);
        StatusChange status = eventHandler.next(statusRequest.getSessionIdentifier());
        response = new WaitForChangeResponse(status);
    } catch (StatusException e) {
        response = new BindingResult(BindingResultCode.WRONG_PARAMETER);
        response.setResultMessage(e.getMessage());
    } catch (Exception e) {
        response = new BindingResult(BindingResultCode.INTERNAL_ERROR);
        LOG.error(e.getMessage(), e);
    }
    return response;
}
Also used : BindingResult(org.openecard.addon.bind.BindingResult) StatusChange(org.openecard.ws.schema.StatusChange)

Example 2 with StatusChange

use of org.openecard.ws.schema.StatusChange in project open-ecard by ecsec.

the class EventHandler method signalEvent.

@Override
public void signalEvent(EventType eventType, EventObject eventData) {
    ConnectionHandleType connectionHandle = eventData.getHandle();
    for (Map.Entry<String, LinkedBlockingQueue<StatusChange>> entry : eventQueues.entrySet()) {
        try {
            LinkedBlockingQueue<StatusChange> queue = entry.getValue();
            StatusChange statusChange = new StatusChange();
            statusChange.setAction(eventType.getEventTypeIdentifier());
            statusChange.setConnectionHandle(connectionHandle);
            queue.put(statusChange);
        } catch (InterruptedException ignore) {
        }
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) StatusChange(org.openecard.ws.schema.StatusChange) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with StatusChange

use of org.openecard.ws.schema.StatusChange in project open-ecard by ecsec.

the class EventHandler method next.

/**
 * @param session
 * @return a StatusChange containing the new status, or null if no eventQueue for the given session exists or if
 *   interrupted
 */
public StatusChange next(String session) {
    // String session = statusChangeRequest.getSessionIdentifier();
    StatusChange handle = null;
    LinkedBlockingQueue<StatusChange> queue = eventQueues.get(session);
    if (queue == null) {
        LOG.error("No queue found for session {}", session);
        return null;
    }
    do {
        try {
            timers.get(session).reschedule(deleteDelay);
            handle = eventQueues.get(session).poll(30, TimeUnit.SECONDS);
            LOG.debug("WaitForChange event pulled from event queue.");
        } catch (InterruptedException ex) {
            return null;
        }
    } while (handle == null);
    return handle;
}
Also used : StatusChange(org.openecard.ws.schema.StatusChange)

Aggregations

StatusChange (org.openecard.ws.schema.StatusChange)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 BindingResult (org.openecard.addon.bind.BindingResult)1