use of org.ow2.proactive.scheduler.common.SchedulerEventListener 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));
}
use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.
the class SchedulerFrontendState method addEventListener.
synchronized SchedulerState addEventListener(SchedulerEventListener sel, boolean myEventsOnly, boolean getCurrentState, SchedulerEvent... events) throws NotConnectedException, PermissionException {
// checking permissions
ListeningUser uIdent = checkPermissionReturningListeningUser("addEventListener", YOU_DO_NOT_HAVE_PERMISSION_TO_ADD_A_LISTENER);
// check if listener is not null
if (sel == null) {
String msg = "Scheduler listener must be not null";
logger.info(msg);
throw new IllegalArgumentException(msg);
}
// check if the listener is a reified remote object
if (!MOP.isReifiedObject(sel)) {
String msg = "Scheduler listener must be a remote object";
logger.info(msg);
throw new IllegalArgumentException(msg);
}
// get the scheduler State
SchedulerState currentState = null;
if (getCurrentState) {
// check get state permission is checked in getState method
currentState = getState(myEventsOnly);
} else {
// check get state permission
handleOnlyMyJobsPermission(myEventsOnly, uIdent.getUser(), YOU_DO_NOT_HAVE_PERMISSION_TO_ADD_A_LISTENER);
}
// prepare user for receiving events
uIdent.getUser().setUserEvents(events);
// set if the user wants to get its events only or every events
uIdent.getUser().setMyEventsOnly(myEventsOnly);
// add the listener to the list of listener for this user.
UniqueID id = PAActiveObject.getContext().getCurrentRequest().getSourceBodyID();
uIdent.setListener(new ClientRequestHandler(this, id, sel));
// cancel timer for this user : session is now managed by events
uIdent.getUser().getSession().cancel();
// return to the user
return currentState;
}
use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.
the class AbstractSchedulerUser method registerListener.
public void registerListener(boolean getInitialState, boolean myEventsOnly, String listenerClazzName) throws SchedulerException, ProActiveException {
try {
if (this.scheduler == null)
throw new IllegalStateException("The user is not connected to the Scheduler yet. " + "Consider calling the connectToScheduler() method first");
SchedulerEventListener schedulerListener = createEventListener(listenerClazzName);
logger.trace("Trying to expose the listener as a remote object");
slExposer = new SchedulerListenerExposer(schedulerListener);
SchedulerEventListener schedulerListenerRemoteRef = slExposer.createRemoteReference();
logger.trace("Trying to register the listener to the Scheduler");
// for the moment, listens only to the Jobs-related events
SchedulerState initialState = scheduler.addEventListener(schedulerListenerRemoteRef, myEventsOnly, getInitialState, // job-related events
SchedulerEvent.JOB_SUBMITTED, SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_PENDING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_PAUSED, SchedulerEvent.JOB_RESUMED, SchedulerEvent.JOB_RESTARTED_FROM_ERROR, SchedulerEvent.JOB_CHANGE_PRIORITY, // task-related events
SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.TASK_WAITING_FOR_RESTART, SchedulerEvent.USERS_UPDATE, // Scheduler state related events
SchedulerEvent.FROZEN, SchedulerEvent.RESUMED, SchedulerEvent.SHUTDOWN, SchedulerEvent.SHUTTING_DOWN, SchedulerEvent.STARTED, SchedulerEvent.STOPPED, SchedulerEvent.KILLED);
if (getInitialState) {
logger.info("Initial state of the scheduler is: " + initialState);
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Class " + listenerClazzName + " is not available on this SchedulerUser's side", e);
} catch (InstantiationException e) {
throw new IllegalArgumentException("Cannot instantiate listener of type " + listenerClazzName, e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Cannot instantiate listener of type " + listenerClazzName, e);
}
}
use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.
the class SchedulerJobSubmitter method createEventListener.
@Override
protected SchedulerEventListener createEventListener(String listenerClazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
logger.trace("Trying to load the listener class " + listenerClazzName);
Class listenerClazz = Class.forName(listenerClazzName);
logger.trace("Trying to instantiate a listener of type " + listenerClazzName);
SchedulerEventListener schedulerListener = (SchedulerEventListener) listenerClazz.newInstance();
logger.trace("Decorating the event listener with " + JobResultDecorator.class.getName());
this.jrListener = new JobResultDecorator(schedulerListener, (AbstractSchedulerUser<JobId>) PAActiveObject.getStubOnThis());
return this.jrListener;
}
use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.
the class SchedulerUser method createEventListener.
@Override
protected SchedulerEventListener createEventListener(String listenerClazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
logger.trace("Trying to load the listener class " + listenerClazzName);
Class listenerClazz = Class.forName(listenerClazzName);
logger.trace("Trying to instantiate a listener of type " + listenerClazzName);
SchedulerEventListener ret = (SchedulerEventListener) listenerClazz.newInstance();
// ugly but necessary; getJobResult MUST be called from the SchedulerUser AO !!
if (ret instanceof JobResultSchedulerListener)
((JobResultSchedulerListener) ret).setResultFetcher((SchedulerUser<JobId>) PAActiveObject.getStubOnThis());
return ret;
}
Aggregations