Search in sources :

Example 6 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project tomee by apache.

the class QuartzResourceAdapter method endpointActivation.

@Override
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    final Scheduler s = scheduler.get();
    if (null == s) {
        throw new ResourceException("Quartz Scheduler is not available");
    }
    try {
        final JobSpec spec = (JobSpec) activationSpec;
        final MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
        spec.setEndpoint(endpoint);
        final Job job = (Job) endpoint;
        final JobDataMap jobDataMap = spec.getDetail().getJobDataMap();
        jobDataMap.put(Data.class.getName(), new Data(job));
        s.scheduleJob(spec.getDetail(), spec.getTrigger());
    } catch (final SchedulerException e) {
        throw new ResourceException("Failed to schedule job", e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) JobDataMap(org.apache.openejb.quartz.JobDataMap) SchedulerException(org.apache.openejb.quartz.SchedulerException) Scheduler(org.apache.openejb.quartz.Scheduler) ResourceException(javax.resource.ResourceException) Job(org.apache.openejb.quartz.Job)

Example 7 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project tomee by apache.

the class SampleResourceAdapter method endpointActivation.

public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    final SampleActivationSpec sampleActivationSpec = (SampleActivationSpec) activationSpec;
    try {
        final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
        final EndpointTarget target = new EndpointTarget(messageEndpoint);
        targets.put(sampleActivationSpec, target);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) ResourceException(javax.resource.ResourceException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Example 8 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project tomee by apache.

the class EndpointFactory method createEndpoint.

@Override
public MessageEndpoint createEndpoint(final XAResource xaResource, final long timeout) throws UnavailableException {
    if (timeout <= 0) {
        return createEndpoint(xaResource);
    }
    final long end = System.currentTimeMillis() + timeout;
    MessageEndpoint messageEndpoint = null;
    while (System.currentTimeMillis() <= end) {
        try {
            messageEndpoint = createEndpoint(xaResource);
            break;
        } catch (final Exception ex) {
        // ignore so we can keep trying
        }
    }
    if (messageEndpoint != null) {
        return messageEndpoint;
    } else {
        throw new UnavailableException("Unable to create end point within the specified timeout " + timeout);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) UnavailableException(javax.resource.spi.UnavailableException) UnavailableException(javax.resource.spi.UnavailableException)

Example 9 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project tomee by apache.

the class SampleResourceAdapter method endpointActivation.

public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    final SampleActivationSpec sampleActivationSpec = (SampleActivationSpec) activationSpec;
    try {
        final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
        final EndpointTarget target = new EndpointTarget(messageEndpoint);
        targets.put(sampleActivationSpec, target);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) IllegalStateException(java.lang.IllegalStateException) ResourceException(javax.resource.ResourceException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Example 10 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project javaee7-samples by javaee-samples.

the class WatchingThread method dispatchEvents.

private void dispatchEvents(List<WatchEvent<?>> events, MessageEndpointFactory messageEndpointFactory) {
    for (WatchEvent<?> event : events) {
        Path path = (Path) event.context();
        try {
            MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
            Class<?> beanClass = resourceAdapter.getBeanClass(messageEndpointFactory);
            for (Method m : beanClass.getMethods()) {
                if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind()) && m.isAnnotationPresent(Created.class) && path.toString().matches(m.getAnnotation(Created.class).value())) {
                    invoke(endpoint, m, path);
                } else if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind()) && m.isAnnotationPresent(Deleted.class) && path.toString().matches(m.getAnnotation(Deleted.class).value())) {
                    invoke(endpoint, m, path);
                } else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(event.kind()) && m.isAnnotationPresent(Modified.class) && path.toString().matches(m.getAnnotation(Modified.class).value())) {
                    invoke(endpoint, m, path);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) Method(java.lang.reflect.Method) WorkException(javax.resource.spi.work.WorkException)

Aggregations

MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)15 ResourceException (javax.resource.ResourceException)5 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)3 UnavailableException (javax.resource.spi.UnavailableException)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 TelnetServer (org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)1 IllegalStateException (java.lang.IllegalStateException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 MessageListener (javax.jms.MessageListener)1 Work (javax.resource.spi.work.Work)1 WorkException (javax.resource.spi.work.WorkException)1 Job (org.apache.openejb.quartz.Job)1 JobDataMap (org.apache.openejb.quartz.JobDataMap)1 Scheduler (org.apache.openejb.quartz.Scheduler)1 SchedulerException (org.apache.openejb.quartz.SchedulerException)1 MessageBeanListener (org.glassfish.ejb.api.MessageBeanListener)1