use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class ConcurrentMethod$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final ConcurrentMethod concurrentMethod, RuntimeContext context) throws Exception {
if (concurrentMethod == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (ConcurrentMethod.class != concurrentMethod.getClass()) {
context.unexpectedSubclass(writer, concurrentMethod, ConcurrentMethod.class);
return;
}
context.beforeMarshal(concurrentMethod, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = concurrentMethod.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(concurrentMethod, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: method
final NamedMethod method = concurrentMethod.method;
if (method != null) {
writer.writeStartElement(prefix, "method", "http://java.sun.com/xml/ns/javaee");
writeNamedMethod(writer, method, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(concurrentMethod, "method");
}
// ELEMENT: lock
final ConcurrentLockType lock = concurrentMethod.lock;
if (lock != null) {
writer.writeStartElement(prefix, "lock", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(toStringConcurrentLockType(concurrentMethod, null, context, lock));
writer.writeEndElement();
}
// ELEMENT: accessTimeout
final Timeout accessTimeout = concurrentMethod.accessTimeout;
if (accessTimeout != null) {
writer.writeStartElement(prefix, "access-timeout", "http://java.sun.com/xml/ns/javaee");
writeTimeout(writer, accessTimeout, context);
writer.writeEndElement();
}
context.afterMarshal(concurrentMethod, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class ConcurrentMethod$JAXB method _read.
public static final ConcurrentMethod _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
// Check for xsi:nil
if (reader.isXsiNil()) {
return null;
}
if (context == null) {
context = new RuntimeContext();
}
final ConcurrentMethod concurrentMethod = new ConcurrentMethod();
context.beforeUnmarshal(concurrentMethod, LifecycleCallback.NONE);
// Check xsi:type
final QName xsiType = reader.getXsiType();
if (xsiType != null) {
if (("concurrent-methodType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
return context.unexpectedXsiType(reader, ConcurrentMethod.class);
}
}
// Read attributes
for (final Attribute attribute : reader.getAttributes()) {
if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: id
final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
context.addXmlId(reader, id, concurrentMethod);
concurrentMethod.id = id;
} else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
context.unexpectedAttribute(attribute, new QName("", "id"));
}
}
// Read elements
for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
if (("method" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: method
final NamedMethod method = readNamedMethod(elementReader, context);
concurrentMethod.method = method;
} else if (("lock" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: lock
final ConcurrentLockType lock = parseConcurrentLockType(elementReader, context, elementReader.getElementAsString());
if (lock != null) {
concurrentMethod.lock = lock;
}
} else if (("access-timeout" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: accessTimeout
final Timeout accessTimeout = readTimeout(elementReader, context);
concurrentMethod.accessTimeout = accessTimeout;
} else {
context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "method"), new QName("http://java.sun.com/xml/ns/javaee", "lock"), new QName("http://java.sun.com/xml/ns/javaee", "access-timeout"));
}
}
context.afterUnmarshal(concurrentMethod, LifecycleCallback.NONE);
return concurrentMethod;
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class FullyInterceptedTest method module.
@Module
public EjbJar module() {
final EjbJar ejbJar = new EjbJar();
final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(FullyInterceptedBean.class));
final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
final InterceptorBinding b = assembly.addInterceptorBinding(new InterceptorBinding(bean));
b.setExcludeDefaultInterceptors(true);
b.setMethod(new NamedMethod("methodWithDefaultInterceptorsExcluded"));
return ejbJar;
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class ScheduleTest method testSchedule.
public void testSchedule() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
//Configure schedule by deployment plan
final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
final Timer subBeanATimer = new Timer();
subBeanATimer.setTimeoutMethod(new NamedMethod("subBeanA", "javax.ejb.Timer"));
final TimerSchedule timerScheduleA = new TimerSchedule();
timerScheduleA.setSecond("2");
timerScheduleA.setMinute("*");
timerScheduleA.setHour("*");
subBeanATimer.setSchedule(timerScheduleA);
subBeanATimer.setInfo("SubBeanAInfo");
subBeanA.getTimer().add(subBeanATimer);
ejbJar.addEnterpriseBean(subBeanA);
//Configure schedule by annotation
final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
ejbJar.addEnterpriseBean(subBeanB);
//Override aroundTimeout annotation by deployment plan
final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
final Timer subBeanCTimer = new Timer();
subBeanCTimer.setTimeoutMethod(new NamedMethod("subBeanC", "javax.ejb.Timer"));
final TimerSchedule timerScheduleC = new TimerSchedule();
timerScheduleC.setSecond("2");
timerScheduleC.setMinute("*");
timerScheduleC.setHour("*");
subBeanCTimer.setSchedule(timerScheduleC);
subBeanCTimer.setInfo("SubBeanCInfo");
subBeanC.getTimer().add(subBeanCTimer);
ejbJar.addEnterpriseBean(subBeanC);
final StatefulBean subBeanM = new StatefulBean(SubBeanM.class);
ejbJar.addEnterpriseBean(subBeanM);
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
countDownLatch.await(1L, TimeUnit.MINUTES);
//A better way for validation ?
int beforeAroundInvocationCount = 0;
int afterAroundInvocationCount = 0;
int timeoutInvocationCount = 0;
final int size;
synchronized (result) {
size = result.size();
for (final Call call : result) {
switch(call) {
case BEAN_BEFORE_AROUNDTIMEOUT:
beforeAroundInvocationCount++;
break;
case BEAN_AFTER_AROUNDTIMEOUT:
afterAroundInvocationCount++;
break;
case TIMEOUT:
timeoutInvocationCount++;
break;
}
}
}
assertEquals(3, beforeAroundInvocationCount);
assertEquals(3, afterAroundInvocationCount);
assertEquals(3, timeoutInvocationCount);
assertEquals(9, size);
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class StatefulConcurrencyTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
assembler.createContainer(statefulContainerInfo);
final EjbJar ejbJar = new EjbJar();
final StatefulBean bean1 = new StatefulBean(MyLocalBeanImpl.class);
final Timeout timeout1 = new Timeout();
timeout1.setTimeout(1000);
timeout1.setUnit(TimeUnit.MILLISECONDS);
final ConcurrentMethod method1 = new ConcurrentMethod();
method1.setMethod(new NamedMethod("*"));
method1.setAccessTimeout(timeout1);
bean1.getConcurrentMethod().add(method1);
final StatefulBean bean2 = new StatefulBean("BeanNegative", MyLocalBeanImpl.class);
final Timeout timeout2 = new Timeout();
timeout2.setTimeout(-1);
timeout2.setUnit(TimeUnit.MILLISECONDS);
final ConcurrentMethod method2 = new ConcurrentMethod();
method2.setMethod(new NamedMethod("*"));
method2.setAccessTimeout(timeout2);
bean2.getConcurrentMethod().add(method2);
ejbJar.addEnterpriseBean(bean1);
ejbJar.addEnterpriseBean(bean2);
assembler.createApplication(config.configureApplication(ejbJar));
}
Aggregations