當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageDriven類代碼示例

本文整理匯總了Java中javax.ejb.MessageDriven的典型用法代碼示例。如果您正苦於以下問題:Java MessageDriven類的具體用法?Java MessageDriven怎麽用?Java MessageDriven使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MessageDriven類屬於javax.ejb包,在下文中一共展示了MessageDriven類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: messageDrivenBean

import javax.ejb.MessageDriven; //導入依賴的package包/類
private static <T> JMSContextMock messageDrivenBean(T bean, Class<? extends T> beanType) {
    if (MessageListener.class.isAssignableFrom(beanType)) {
        MessageDriven md = beanType.getAnnotation(MessageDriven.class);
        Collection<ActivationConfigProperty> properties = asList(md.activationConfig());
        ActiveMQDestination destination = lookupDestination(properties);
        CTX.startBrokerIfAbsent();
        try {
            JMSContextMock ctx = new JMSContextMock(CTX.getConnectionFactory(),
                    lookupClientId(properties, destination.getPhysicalName()),
                    false,
                    lookupAcknowledgeMode(properties));
            createConsumer(properties, ctx.getSession(), destination)
                    .setMessageListener(new JMS20MessageListenerDecorator<>((MessageListener) bean));
            return ctx;
        } catch (JMSException e) {
            throw new EJBException(e.getLocalizedMessage(), e);
        }
    } else {
        throw new EJBException("The message driven bean \""
                + beanType.getName()
                + "\" must implement the appropriate message listener interface \""
                + MessageDriven.class.getName()
                + "\".");
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:26,代碼來源:MessageDrivenContext.java

示例2: beans

import javax.ejb.MessageDriven; //導入依賴的package包/類
public <X> void beans(
        final @Observes ProcessAnnotatedType<X> processBean
) {
    final MessageDriven annotation = processBean.getAnnotatedType().getAnnotation(MessageDriven.class);
    if (annotation != null) {
        final Class<X> javaClass = processBean.getAnnotatedType().getJavaClass();
        if (!MessageListener.class.isAssignableFrom(javaClass)) {
            throw new TestEEfiException("The @MessageDriven bean " + javaClass.getName()
                    + " does not implement MessageListener"
            );
        }
        registry.register(annotation, (Class<? extends MessageListener>) javaClass);
    }
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:15,代碼來源:JmsExtension.java

示例3: bindContext

import javax.ejb.MessageDriven; //導入依賴的package包/類
@Override
public <T> T bindContext(T bean, Class<?> beanType) {
    if (beanType.isAnnotationPresent(MessageDriven.class)) {
        MDCTX.get().computeIfAbsent(bean, b -> messageDrivenBean(bean, beanType));
    }
    return bean;
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:8,代碼來源:MessageDrivenContext.java

示例4: lookupOf

import javax.ejb.MessageDriven; //導入依賴的package包/類
@Override
public <T> Optional<Object> lookupOf(Class<?> declaredInjectionType, Resource injectionAnnotation, T bean, Class<? extends T> beanType) {
    String mapping = injectionAnnotation.mappedName();
    if (mapping == null) mapping = injectionAnnotation.lookup();
    switch (mapping) {
        case "jms/ConnectionFactory": // Java EE spec
        case "java:/ConnectionFactory": // Java EE spec
        case "/ConnectionFactory": // JBoss
        case "java:comp/DefaultJMSConnectionFactory": // JBoss
        case "java:jboss/DefaultJMSConnectionFactory": // JBoss
        case "java:/JmsXA":
            return of(connectionFactory);

        case "java:jms/queue/test": // Java EE spec
        case "jms/queue/test": // Java EE spec
        case "queue/test": // JBoss
        case "/jms/queue/test": // JBoss
        case "/queue/test": // JBoss
            sanityCheckQueue(injectionAnnotation.type(), mapping, beanType);
            if (beanType.isAnnotationPresent(MessageDriven.class)) {
                if (MessageListener.class.isAssignableFrom(beanType)) {
                    try {
                        consumer.getMessageConsumer().setMessageListener((MessageListener) bean);
                    } catch (JMSException e) {
                        throw new IllegalStateException(e.getLocalizedMessage(), e);
                    }
                } else {
                    throw new EJBException("The message driven bean \""
                            + beanType.getName()
                            + "\" must implement the appropriate message listener interface \""
                            + MessageDriven.class.getName()
                            + "\".");
                }
            }
            return of(producer.getDestination());

        default:
            return empty();
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:41,代碼來源:JmsResource.java

示例5: register

import javax.ejb.MessageDriven; //導入依賴的package包/類
public <X extends  MessageListener> void register(final MessageDriven annotation, final Class<X> javaClass) {
    LOG.info("{} -> {}", annotation.mappedName(), javaClass.getName());
    messageDrivenBeans.put(annotation.mappedName(), javaClass);
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:5,代碼來源:MessageDrivenBeanRegistry.java

示例6: getEjbName

import javax.ejb.MessageDriven; //導入依賴的package包/類
private String getEjbName(final MessageDriven mdb, final Class<?> beanClass) {
    return mdb.name().isEmpty() ? beanClass.getSimpleName() : mdb.name();
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:4,代碼來源:AnnotationDeployer.java

示例7: isValidEjbAnnotationUsage

import javax.ejb.MessageDriven; //導入依賴的package包/類
private boolean isValidEjbAnnotationUsage(final Class annotationClass, final Annotated<Class<?>> beanClass, final String ejbName, final EjbModule ejbModule) {
    final List<Class<? extends Annotation>> annotations = new ArrayList(Arrays.asList(Singleton.class, Stateless.class, Stateful.class, MessageDriven.class));
    annotations.remove(annotationClass);

    final boolean b = true;
    for (final Class<? extends Annotation> secondAnnotation : annotations) {
        final Annotation annotation = beanClass.getAnnotation(secondAnnotation);

        if (annotation == null) {
            continue;
        }

        String secondEjbName = null;
        if (annotation instanceof Stateful) {
            secondEjbName = getEjbName((Stateful) annotation, beanClass.get());
        } else if (annotation instanceof Stateless) {
            secondEjbName = getEjbName((Stateless) annotation, beanClass.get());
        } else if (annotation instanceof Singleton) {
            secondEjbName = getEjbName((Singleton) annotation, beanClass.get());
        } else if (annotation instanceof MessageDriven) {
            secondEjbName = getEjbName((MessageDriven) annotation, beanClass.get());
        }

        if (ejbName.equals(secondEjbName)) {
            ejbModule.getValidation().fail(ejbName, "multiplyAnnotatedAsBean", annotationClass.getSimpleName(), secondAnnotation.getSimpleName(), ejbName, beanClass.get().getName());
        }
    }

    if (beanClass.get().isInterface()) {
        if (!CheckClasses.isAbstractAllowed(beanClass.get())) {
            ejbModule.getValidation().fail(ejbName, "interfaceAnnotatedAsBean", annotationClass.getSimpleName(), beanClass.get().getName());
            return false;
        }
    } else if (Modifier.isAbstract(beanClass.get().getModifiers())) {
        if (!CheckClasses.isAbstractAllowed(beanClass.get())) {
            ejbModule.getValidation().fail(ejbName, "abstractAnnotatedAsBean", annotationClass.getSimpleName(), beanClass.get().getName());
            return false;
        }
    }

    return b;
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:43,代碼來源:AnnotationDeployer.java

示例8: processInjectionTarget

import javax.ejb.MessageDriven; //導入依賴的package包/類
/**
 * Replaces the meta data of the {@link ProcessAnnotatedType}.
 * 
 * <p>
 * The ProcessAnnotatedType's meta data will be replaced, if the annotated type has one of the following annotations:
 * <ul>
 * <li> {@link Stateless}
 * <li> {@link MessageDriven}
 * <li> {@link Interceptor}
 * <li> {@link Singleton}
 * </ul>
 *
 * @param <X> the type of the ProcessAnnotatedType
 * @param pat the annotated type representing the class being processed
 */
public <X> void processInjectionTarget(@Observes @WithAnnotations({Stateless.class, MessageDriven.class, Interceptor.class, Singleton.class}) ProcessAnnotatedType<X> pat) {
    if (pat.getAnnotatedType().isAnnotationPresent(Stateless.class) || pat.getAnnotatedType().isAnnotationPresent(MessageDriven.class)) {
        modifiyAnnotatedTypeMetadata(pat);
    } else if (pat.getAnnotatedType().isAnnotationPresent(Interceptor.class)) {
        processInterceptorDependencies(pat);
    } else if(pat.getAnnotatedType().isAnnotationPresent(Singleton.class)) {
        addApplicationScopedAndTransactionalToSingleton(pat);
    }
}
 
開發者ID:NovaTecConsulting,項目名稱:BeanTest,代碼行數:25,代碼來源:BeanTestExtension.java


注:本文中的javax.ejb.MessageDriven類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。