Search in sources :

Example 1 with DisconnectionAwareSchedulerEventListener

use of org.ow2.proactive.scheduler.rest.DisconnectionAwareSchedulerEventListener in project scheduling by ow2-proactive.

the class RestSmartProxyImpl method notifyDisconnection.

/**
 * notify the socket disconnection
 */
@Override
public void notifyDisconnection() {
    if (!terminating) {
        logger.warn("Websocket disconnection notification received.");
        for (SchedulerEventListenerExtended listener : eventListeners) {
            if (listener instanceof DisconnectionAwareSchedulerEventListener) {
                ((DisconnectionAwareSchedulerEventListener) listener).notifyDisconnection();
            }
        }
        try {
            registerAsListener();
            syncAwaitedJobs();
        } catch (Exception e) {
            logger.error("Error while reconnecting", e);
        }
    }
}
Also used : SchedulerEventListenerExtended(org.ow2.proactive.scheduler.smartproxy.common.SchedulerEventListenerExtended) DisconnectionAwareSchedulerEventListener(org.ow2.proactive.scheduler.rest.DisconnectionAwareSchedulerEventListener) TimeoutException(java.util.concurrent.TimeoutException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException)

Example 2 with DisconnectionAwareSchedulerEventListener

use of org.ow2.proactive.scheduler.rest.DisconnectionAwareSchedulerEventListener in project scheduling by ow2-proactive.

the class SchedulerEventReceiver method openAndReceive.

@SuppressWarnings("rawtypes")
private void openAndReceive(final SchedulerEventListener eventListener, boolean myEventsOnly, SchedulerEvent... events) throws IOException {
    Client client = ClientFactory.getDefault().newClient();
    AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
    if (insecure) {
        builder = builder.setAcceptAnyCertificate(true).setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    }
    AsyncHttpClientConfig httpClientConfig = builder.build();
    AsyncHttpClient httpClient = new AsyncHttpClient(httpClientConfig);
    socket = client.create(client.newOptionsBuilder().runtime(httpClient).reconnect(false).build());
    EventNotificationHandler notificationHandler = new EventNotificationHandler(eventListener);
    socket.on(Event.MESSAGE, notificationHandler);
    socket.on(Event.CLOSE, new Function() {

        public void on(Object t) {
            SchedulerEventReceiver.logger.info("#### Websocket connection is closed ####");
            if (eventListener instanceof DisconnectionAwareSchedulerEventListener) {
                ((DisconnectionAwareSchedulerEventListener) eventListener).notifyDisconnection();
            }
        }
    });
    // initialize the connection
    RequestBuilder requestBuilder = client.newRequestBuilder();
    requestBuilder.method(Request.METHOD.GET);
    requestBuilder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    // authentication header
    requestBuilder.header("sessionid", sessionId);
    requestBuilder.uri(eventingUrl(restServerUrl));
    requestBuilder.encoder(new EventSubscriptionEncoder());
    requestBuilder.decoder(new EventNotificationDecoder());
    requestBuilder.transport(Request.TRANSPORT.WEBSOCKET);
    socket.open(requestBuilder.build());
    // submit subscription request
    EventSubscription eventSubscription = new EventSubscription(myEventsOnly, asStringArray(events));
    socket.fire(EventCodecUtil.toJsonString(eventSubscription));
}
Also used : RequestBuilder(org.atmosphere.wasync.RequestBuilder) RequestBuilder(org.atmosphere.wasync.RequestBuilder) Function(org.atmosphere.wasync.Function) EventSubscription(org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventSubscription) AsyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig) Client(org.atmosphere.wasync.Client) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) AsyncHttpClient(com.ning.http.client.AsyncHttpClient)

Aggregations

AsyncHttpClient (com.ning.http.client.AsyncHttpClient)1 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1 TimeoutException (java.util.concurrent.TimeoutException)1 Client (org.atmosphere.wasync.Client)1 Function (org.atmosphere.wasync.Function)1 RequestBuilder (org.atmosphere.wasync.RequestBuilder)1 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)1 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)1 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)1 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)1 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)1 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)1 DisconnectionAwareSchedulerEventListener (org.ow2.proactive.scheduler.rest.DisconnectionAwareSchedulerEventListener)1 SchedulerEventListenerExtended (org.ow2.proactive.scheduler.smartproxy.common.SchedulerEventListenerExtended)1 EventSubscription (org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventSubscription)1