javax.resource.spi.endpoint.MessageEndpoint Java Examples

The following examples show how to use javax.resource.spi.endpoint.MessageEndpoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuartzResourceAdapter.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #2
Source File: EndpointFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
public EndpointFactory(final ActivationSpec activationSpec, final BaseMdbContainer container, final BeanContext beanContext, final MdbInstanceFactory instanceFactory, final MdbInstanceManager instanceManager, final XAResourceWrapper xaResourceWrapper, boolean usePool) {
    this.activationSpec = activationSpec;
    this.container = container;
    this.beanContext = beanContext;
    this.instanceFactory = instanceFactory;
    this.instanceManager = instanceManager;
    classLoader = container.getMessageListenerInterface().getClassLoader();
    interfaces = new Class[]{container.getMessageListenerInterface(), MessageEndpoint.class};
    this.xaResourceWrapper = xaResourceWrapper;
    this.usePool = usePool;
    final BeanContext.ProxyClass proxyClass = beanContext.get(BeanContext.ProxyClass.class);
    if (proxyClass == null) {
        proxy = LocalBeanProxyFactory.createProxy(beanContext.getBeanClass(), beanContext.getClassLoader(), interfaces);
        beanContext.set(BeanContext.ProxyClass.class, new BeanContext.ProxyClass(beanContext, interfaces));
    } else {
        proxy = proxyClass.getProxy();
    }
}
 
Example #3
Source File: EndpointFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: TestActivation.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Start the activation
 * @throws ResourceException Thrown if an error occurs
 */
public void start() throws ResourceException
{
   try
   {
      Method m = TestMessageListener.class.getMethod("onMessage", new Class<?>[] {String.class});
      
      MessageEndpoint me = endpointFactory.createEndpoint(null);
      me.beforeDelivery(m);

      TestMessageListener tml = (TestMessageListener)me;
      tml.onMessage(spec.getName());
      
      me.afterDelivery();
      me.release();
   }
   catch (ResourceException re)
   {
      throw re;
   }
   catch (Exception e)
   {
      throw new ResourceException(e);
   }
}
 
Example #5
Source File: MDBActivationWork.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Performs the work
 */
public void run() {
    MDBInvoker invoker = createInvoker();
    MessageEndpoint mep = invoker.getMessageEndpoint();
    if (mep == null) {
        return;
    }

    ClassLoader savedClassLoader = null;

    try {
        savedClassLoader = Thread.currentThread().getContextClassLoader();
        ClassLoader classLoader = mep.getClass().getClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        activate(invoker, classLoader);
    } finally {
        invoker.releaseEndpoint(mep);
        if (savedClassLoader != null) {
            Thread.currentThread().setContextClassLoader(savedClassLoader);
        }
    }
}
 
Example #6
Source File: MDBInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes endpoint factory to create message endpoint (event driven bean).
 * It will retry if the event driven bean is not yet available.
 */
private MessageEndpoint createMessageEndpoint() {
    MessageEndpoint ep = null;
    for (int i = 0; i < MAX_ATTEMPTS; i++) {
        try {
            ep = endpointFactory.createEndpoint(null);
            break;
        } catch (UnavailableException e) {
            LOG.fine("Target endpoint activation in progress.  Will retry.");
            try {
                Thread.sleep(RETRY_SLEEP);
            } catch (InterruptedException e1) {
                // ignore
            }
        }
    }

    return ep;
}
 
Example #7
Source File: CustomMdbContainerTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
    final EmailAccountInfo accountInfo = (EmailAccountInfo) activationSpec;

    final EmailConsumer emailConsumer = consumers.remove(accountInfo.getAddress());
    final MessageEndpoint endpoint = (MessageEndpoint) emailConsumer;
    endpoint.release();
}
 
Example #8
Source File: EndpointFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
    if (xaResource != null && xaResourceWrapper != null) {
        xaResource = xaResourceWrapper.wrap(xaResource, container.getContainerID().toString());
    }

    InvocationHandler endpointHandler = null;
    if (usePool) {
        endpointHandler = new PoolEndpointHandler(container, beanContext, instanceManager, xaResource);
    } else {
        endpointHandler = new EndpointHandler(container, beanContext, instanceFactory, xaResource);
    }

    try {
        return (MessageEndpoint) LocalBeanProxyFactory.constructProxy(proxy, endpointHandler);
    } catch (final InternalError e) { // should be useless
        //try to create the proxy with tccl once again.
        try {
            return MessageEndpoint.class.cast(LocalBeanProxyFactory.newProxyInstance(Thread.currentThread().getContextClassLoader(), endpointHandler, beanContext.getBeanClass(), interfaces));
        } catch (final InternalError ie) {
            try {
                return MessageEndpoint.class.cast(LocalBeanProxyFactory.newProxyInstance(classLoader, endpointHandler, beanContext.getBeanClass(), interfaces));
            } catch (final InternalError ie2) {
                // no-op
            }
        }
        throw e;
    }
}
 
Example #9
Source File: SampleResourceAdapter.java    From tomee with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #10
Source File: SampleResourceAdapter.java    From tomee with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #11
Source File: MdbConfigTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    assertNotNull("messageEndpointFactory is null", messageEndpointFactory);
    assertNotNull("activationSpec is null", activationSpec);
    assertTrue("activationSpec should be an instance of FakeActivationSpec", activationSpec instanceof FakeActivationSpec);

    final MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
    assertNotNull("endpoint is null", endpoint);
    assertTrue("endpoint should be an instance of FakeMessageListener", endpoint instanceof FakeMessageListener);
}
 
Example #12
Source File: SampleResourceAdapter.java    From tomee with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #13
Source File: AbstractMessageEndpointFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * The standard JCA 1.5 version of {@code createEndpoint}.
 * <p>This implementation delegates to {@link #createEndpointInternal()},
 * initializing the endpoint's XAResource before the endpoint gets invoked.
 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
	AbstractMessageEndpoint endpoint = createEndpointInternal();
	endpoint.initXAResource(xaResource);
	return endpoint;
}
 
Example #14
Source File: DispatchMDBInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Object getServiceObject(Exchange context) {
    MessageEndpoint ep = null;
    MessageEndpoint epFromMessage = null;

    if (context != null) {
        epFromMessage = context.getInMessage().getContent(MessageEndpoint.class);
    }

    if (epFromMessage == null) {
        ep = getMessageEndpoint();
    } else {
        ep = epFromMessage;
    }

    Object target = null;

    if (ep == null) {
        LOG.log(Level.SEVERE, "Failed to obtain MessageEndpoint");
        return null;
    }

    try {
        target = ((DispatchMDBMessageListener)ep)
            .lookupTargetObject(targetJndiName);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Failed to obtain service object " + targetJndiName, e);
        return null;
    } finally {
        if (epFromMessage == null) {
            releaseEndpoint(ep);
        }
    }

    return target;
}
 
Example #15
Source File: AutoConfigMdbContainerTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
    final EmailAccountInfo accountInfo = (EmailAccountInfo) activationSpec;

    final EmailConsumer emailConsumer = consumers.remove(accountInfo.getAddress());
    final MessageEndpoint endpoint = (MessageEndpoint) emailConsumer;
    endpoint.release();
}
 
Example #16
Source File: AbstractMessageEndpointFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * The standard JCA 1.5 version of {@code createEndpoint}.
 * <p>This implementation delegates to {@link #createEndpointInternal()},
 * initializing the endpoint's XAResource before the endpoint gets invoked.
 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
	AbstractMessageEndpoint endpoint = createEndpointInternal();
	endpoint.initXAResource(xaResource);
	return endpoint;
}
 
Example #17
Source File: AbstractMessageEndpointFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * The alternative JCA 1.6 version of {@code createEndpoint}.
 * <p>This implementation delegates to {@link #createEndpointInternal()},
 * ignoring the specified timeout. It is only here for JCA 1.6 compliance.
 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource, long timeout) throws UnavailableException {
	AbstractMessageEndpoint endpoint = createEndpointInternal();
	endpoint.initXAResource(xaResource);
	return endpoint;
}
 
Example #18
Source File: GenericMessageEndpointFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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(getMessageListener());
	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint);
	introduction.suppressInterface(MethodInterceptor.class);
	proxyFactory.addAdvice(introduction);
	return (MessageEndpoint) proxyFactory.getProxy();
}
 
Example #19
Source File: AbstractMessageEndpointFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * The standard JCA 1.5 version of {@code createEndpoint}.
 * <p>This implementation delegates to {@link #createEndpointInternal()},
 * initializing the endpoint's XAResource before the endpoint gets invoked.
 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
	AbstractMessageEndpoint endpoint = createEndpointInternal();
	endpoint.initXAResource(xaResource);
	return endpoint;
}
 
Example #20
Source File: AbstractMessageEndpointFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * The alternative JCA 1.6 version of {@code createEndpoint}.
 * <p>This implementation delegates to {@link #createEndpointInternal()},
 * ignoring the specified timeout. It is only here for JCA 1.6 compliance.
 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource, long timeout) throws UnavailableException {
	AbstractMessageEndpoint endpoint = createEndpointInternal();
	endpoint.initXAResource(xaResource);
	return endpoint;
}
 
Example #21
Source File: GenericMessageEndpointFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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(getMessageListener());
	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint);
	introduction.suppressInterface(MethodInterceptor.class);
	proxyFactory.addAdvice(introduction);
	return (MessageEndpoint) proxyFactory.getProxy();
}
 
Example #22
Source File: AbstractMessageEndpointFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The standard JCA 1.5 version of {@code createEndpoint}.
 * <p>This implementation delegates to {@link #createEndpointInternal()},
 * initializing the endpoint's XAResource before the endpoint gets invoked.
 */
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
	AbstractMessageEndpoint endpoint = createEndpointInternal();
	endpoint.initXAResource(xaResource);
	return endpoint;
}
 
Example #23
Source File: NoMessageDeliveryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
    final EmailAccountInfo accountInfo = (EmailAccountInfo) activationSpec;

    final EmailConsumer emailConsumer = consumers.remove(accountInfo.getAddress());
    final MessageEndpoint endpoint = (MessageEndpoint) emailConsumer;
    endpoint.release();
}
 
Example #24
Source File: GenericMessageEndpointFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #25
Source File: GenericMessageEndpointFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #26
Source File: ActiveMQRATestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
   if (xaResource != null) {
      endpoint.setXAResource(xaResource);
   }
   return endpoint;
}
 
Example #27
Source File: MDBMultipleHandlersServerDisconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
   TestEndpoint retEnd = new TestEndpoint();
   if (xaResource != null) {
      retEnd.setXAResource(xaResource);
   }
   return retEnd;
}
 
Example #28
Source File: MdbTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public MessageEndpoint createEndpoint(final XAResource xaResource) throws UnavailableException {
    try {
        return new JmsEndpoint(connectionFactory);
    } catch (final JMSException e) {
        e.printStackTrace();
        throw new UnavailableException(e);
    }
}
 
Example #29
Source File: SampleResourceAdapter.java    From tomee with Apache License 2.0 4 votes vote down vote up
public EndpointTarget(final MessageEndpoint messageEndpoint) {
    this.messageEndpoint = messageEndpoint;
}
 
Example #30
Source File: ResourcesJMXTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    final MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
}