Search in sources :

Example 1 with SEPABindingsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException in project SEPA by arces-wot.

the class Consumer method onBrokenConnection.

@Override
public void onBrokenConnection(ErrorResponse errorResponse) {
    logger.warn("onBrokenConnection");
    subscribed = false;
    // Auto reconnection mechanism
    if (appProfile.reconnect()) {
        try {
            protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID), appProfile.getSubscribePort(subID), appProfile.getSubscribePath(subID), this, sm);
            client = new SPARQL11SEProtocol(protocol, sm);
        } catch (SEPASecurityException | SEPAProtocolException e1) {
            logger.error(e1.getMessage());
            return;
        }
        while (!subscribed) {
            try {
                subscribe(TIMEOUT, NRETRY);
            } catch (SEPASecurityException | SEPAPropertiesException | SEPAProtocolException | SEPABindingsException e) {
                logger.error(e.getMessage());
                if (logger.isTraceEnabled())
                    e.printStackTrace();
            }
            try {
                synchronized (client) {
                    client.wait(TIMEOUT);
                }
            } catch (InterruptedException e) {
                logger.error(e.getMessage());
                if (logger.isTraceEnabled())
                    e.printStackTrace();
            }
        }
    }
}
Also used : SPARQL11SEProtocol(it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) WebsocketSubscriptionProtocol(it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol)

Example 2 with SEPABindingsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException in project SEPA by arces-wot.

the class ForcedBindings method setBindingValue.

/**
 * Sets the binding value.
 *
 * @param variable the variable
 * @param value the value
 * @param datatype the datatype
 */
public void setBindingValue(String variable, String value, String datatype) throws SEPABindingsException {
    if (variable == null || value == null)
        throw new SEPABindingsException("One or more arguments are null");
    try {
        solution.getAsJsonObject(variable).add("value", new JsonPrimitive(value));
        solution.getAsJsonObject(variable).add("datatype", new JsonPrimitive(datatype));
    } catch (Exception e) {
        throw new SEPABindingsException(String.format("Variable not found: %s", variable));
    }
}
Also used : SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) JsonPrimitive(com.google.gson.JsonPrimitive) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException)

Example 3 with SEPABindingsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException in project SEPA by arces-wot.

the class ITPattern method genericClientDoubleSubscribe.

@RepeatedTest(ConfigurationProvider.REPEATED_TEST)
@Timeout(10)
public void genericClientDoubleSubscribe() {
    try {
        genericClient = new GenericClient(provider.getJsap(), handler);
        genericClient.subscribe("RANDOM", null, "first", provider.TIMEOUT, provider.NRETRY);
        genericClient.subscribe("RANDOM1", null, "second", provider.TIMEOUT, provider.NRETRY);
        handler.waitSubscribes(2);
        Response ret = genericClient.update("RANDOM", null, provider.TIMEOUT, provider.NRETRY);
        assertFalse(ret.isError(), ret.toString());
        ret = genericClient.update("RANDOM1", null, provider.TIMEOUT, provider.NRETRY);
        assertFalse(ret.isError(), ret.toString());
        handler.waitEvents(4);
        genericClient.unsubscribe(handler.getSpuid("first"), provider.TIMEOUT, provider.NRETRY);
        genericClient.unsubscribe(handler.getSpuid("second"), provider.TIMEOUT, provider.NRETRY);
        handler.waitUnsubscribes(2);
    } catch (SEPAProtocolException | SEPASecurityException | SEPAPropertiesException | SEPABindingsException | InterruptedException | IOException e) {
        e.printStackTrace();
        assertFalse(true, e.getMessage());
    }
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Timeout(org.junit.jupiter.api.Timeout)

Example 4 with SEPABindingsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException in project SEPA by arces-wot.

the class StressUsingPAC method subscribeAndUpdateRaceDetection.

@RepeatedTest(ConfigurationProvider.REPEATED_TEST)
public // @Timeout(10)
void subscribeAndUpdateRaceDetection() throws InterruptedException, SEPASecurityException, IOException, SEPAPropertiesException, SEPAProtocolException, SEPABindingsException {
    Thread pub = new Thread() {

        public void run() {
            for (int i = 0; i < 500; i++) {
                try {
                    randomProducer.update(provider.TIMEOUT, provider.NRETRY);
                } catch (SEPASecurityException | SEPAPropertiesException | SEPABindingsException | SEPAProtocolException e) {
                    assertFalse(true, "Failed on update: " + i + " " + e.getMessage());
                }
            }
        }
    };
    Thread sub = new Thread() {

        public void run() {
            for (int i = 0; i < 500; i++) {
                try {
                    consumerRandom1 = new ConsumerTestUnit(provider, "RANDOM1");
                    consumerRandom1.syncSubscribe(provider.TIMEOUT, provider.NRETRY);
                    consumerRandom1.close();
                    consumerAll = new ConsumerTestUnit(provider, "ALL");
                    consumerAll.syncSubscribe(provider.TIMEOUT, provider.NRETRY);
                    consumerAll.close();
                } catch (SEPASecurityException | SEPAPropertiesException | SEPABindingsException | SEPAProtocolException | IOException | InterruptedException e) {
                    assertFalse(true, "Failed on subscribe: " + i + " " + e.getMessage());
                }
            }
        }
    };
    pub.start();
    sub.start();
    synchronized (pub) {
        pub.wait();
    }
    synchronized (sub) {
        sub.wait();
    }
}
Also used : ConsumerTestUnit(it.unibo.arces.wot.sepa.ConsumerTestUnit) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 5 with SEPABindingsException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException in project SEPA by arces-wot.

the class AggregatorTestUnit method onResults.

@Override
public void onResults(ARBindingsResults results) {
    synchronized (this) {
        notificationReceived = true;
        notify();
    }
    try {
        Response ret = update();
        if (ret.isError())
            logger.error(ret);
    } catch (SEPASecurityException | SEPAProtocolException | SEPAPropertiesException | SEPABindingsException e) {
        logger.error(e);
    }
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)

Aggregations

SEPABindingsException (it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException)7 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)5 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)5 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)5 Response (it.unibo.arces.wot.sepa.commons.response.Response)3 IOException (java.io.IOException)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 Timeout (org.junit.jupiter.api.Timeout)2 JsonPrimitive (com.google.gson.JsonPrimitive)1 ConsumerTestUnit (it.unibo.arces.wot.sepa.ConsumerTestUnit)1 SPARQL11SEProtocol (it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol)1 WebsocketSubscriptionProtocol (it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol)1