Search in sources :

Example 1 with ResourceIdRequestResponseMessage

use of org.apache.asterix.runtime.message.ResourceIdRequestResponseMessage in project asterixdb by apache.

the class GlobalResourceIdFactory method createId.

@Override
public long createId() throws HyracksDataException {
    try {
        ResourceIdRequestResponseMessage reponse = null;
        //if there already exists a response, use it
        if (!resourceIdResponseQ.isEmpty()) {
            synchronized (resourceIdResponseQ) {
                if (!resourceIdResponseQ.isEmpty()) {
                    reponse = resourceIdResponseQ.take();
                }
            }
        }
        //if no response available or it has an exception, request a new one
        if (reponse == null || reponse.getException() != null) {
            ResourceIdRequestMessage msg = new ResourceIdRequestMessage(nodeId);
            ((INCMessageBroker) serviceCtx.getMessageBroker()).sendMessageToCC(msg);
            reponse = resourceIdResponseQ.take();
            if (reponse.getException() != null) {
                throw new HyracksDataException(reponse.getException().getMessage());
            }
        }
        return reponse.getResourceId();
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : ResourceIdRequestMessage(org.apache.asterix.runtime.message.ResourceIdRequestMessage) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) ResourceIdRequestResponseMessage(org.apache.asterix.runtime.message.ResourceIdRequestResponseMessage) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

INCMessageBroker (org.apache.asterix.common.messaging.api.INCMessageBroker)1 ResourceIdRequestMessage (org.apache.asterix.runtime.message.ResourceIdRequestMessage)1 ResourceIdRequestResponseMessage (org.apache.asterix.runtime.message.ResourceIdRequestResponseMessage)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1