Search in sources :

Example 1 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project wildfly by wildfly.

the class TelnetResourceAdapter method endpointActivation.

@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
    final TelnetActivationSpec telnetActivationSpec = (TelnetActivationSpec) activationSpec;
    final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
    // This messageEndpoint instance is also castable to the ejbClass of the MDB
    final TelnetListener telnetListener = (TelnetListener) messageEndpoint;
    try {
        final TelnetServer telnetServer = new TelnetServer(telnetActivationSpec, telnetListener, port);
        workManager.scheduleWork(new Work() {

            @Override
            public void release() {
            }

            @Override
            public void run() {
                try {
                    telnetServer.activate();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, 0, null, null);
        activated.put(port, telnetServer);
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) TelnetListener(org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener) Work(javax.resource.spi.work.Work) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) TelnetServer(org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer)

Example 2 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project wildfly by wildfly.

the class SimpleResourceAdapter method endpointActivation.

/**
     * Send a message to the MDB right after the MDB endpoint is activated.
     * Using reflection to pick a method to invoke - see EJB 3.2 spec section 5.4.3
     */
@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
    log.trace("SimpleResourceAdapter activating MDB endpoint and sending a message to it");
    Class<?> endpointClass = messageEndpointFactory.getEndpointClass();
    try {
        Method methodToInvoke = endpointClass.getMethod(((SimpleActivationSpec) activationSpec).getMethodName(), String.class);
        MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
        this.endpoint = endpoint;
        methodToInvoke.invoke(endpoint, "Hello world");
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) ResourceException(javax.resource.ResourceException) Method(java.lang.reflect.Method) ResourceException(javax.resource.ResourceException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Example 3 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 4 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)

Example 5 with MessageEndpoint

use of javax.resource.spi.endpoint.MessageEndpoint in project spring-framework by spring-projects.

the class GenericMessageEndpointFactory method createEndpoint.

/**
	 * Wrap each concrete endpoint instance with an AOP proxy,
	 * exposing the message listener's interfaces as well as the
	 * endpoint SPI through an AOP introduction.
	 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
    GenericMessageEndpoint endpoint = (GenericMessageEndpoint) super.createEndpoint(xaResource);
    ProxyFactory proxyFactory = new ProxyFactory(this.messageListener);
    DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint);
    introduction.suppressInterface(MethodInterceptor.class);
    proxyFactory.addAdvice(introduction);
    return (MessageEndpoint) proxyFactory.getProxy();
}
Also used : DelegatingIntroductionInterceptor(org.springframework.aop.support.DelegatingIntroductionInterceptor) MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Aggregations

MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)9 ResourceException (javax.resource.ResourceException)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 UnavailableException (javax.resource.spi.UnavailableException)2 TelnetServer (org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MessageListener (javax.jms.MessageListener)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)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 TelnetListener (org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 DelegatingIntroductionInterceptor (org.springframework.aop.support.DelegatingIntroductionInterceptor)1