use of javax.resource.ResourceException 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);
}
}
use of javax.resource.ResourceException in project tomee by apache.
the class MdbInstanceManager method deploy.
public void deploy(final BeanContext beanContext, final ActivationSpec activationSpec, final EndpointFactory endpointFactory) throws OpenEJBException {
if (inboundRecovery != null) {
inboundRecovery.recover(resourceAdapter, activationSpec, containerID.toString());
}
final ObjectRecipe recipe = PassthroughFactory.recipe(new Pool.Builder(poolBuilder));
recipe.allow(Option.CASE_INSENSITIVE_FACTORY);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.setAllProperties(beanContext.getProperties());
final Pool.Builder builder = (Pool.Builder) recipe.create();
setDefault(builder.getMaxAge(), TimeUnit.HOURS);
setDefault(builder.getIdleTimeout(), TimeUnit.MINUTES);
setDefault(builder.getInterval(), TimeUnit.MINUTES);
final InstanceSupplier supplier = new InstanceSupplier(beanContext);
builder.setSupplier(supplier);
builder.setExecutor(executor);
builder.setScheduledExecutor(scheduledExecutor);
final int min = builder.getMin();
final long maxAge = builder.getMaxAge().getTime(TimeUnit.MILLISECONDS);
final double maxAgeOffset = builder.getMaxAgeOffset();
final Data data = new Data(builder.build(), accessTimeout, closeTimeout);
MdbContext mdbContext = new MdbContext(securityService, data::flush);
try {
final Context context = beanContext.getJndiEnc();
context.bind("comp/EJBContext", mdbContext);
context.bind("comp/TimerService", new TimerServiceWrapper());
} catch (final NamingException e) {
throw new OpenEJBException("Failed to bind EJBContext/TimerService", e);
}
beanContext.set(EJBContext.class, mdbContext);
data.setBaseContext(mdbContext);
beanContext.setContainerData(data);
final MBeanServer server = LocalMBeanServer.get();
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("MessageDrivenBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
// register the invocation stats interceptor
try {
final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
// activate the endpoint
try {
final MdbPoolContainer.MdbActivationContext activationContext = new MdbPoolContainer.MdbActivationContext(Thread.currentThread().getContextClassLoader(), beanContext, resourceAdapter, endpointFactory, activationSpec);
activationContexts.put(beanContext, activationContext);
boolean activeOnStartup = true;
String activeOnStartupSetting = beanContext.getActivationProperties().get("MdbActiveOnStartup");
if (activeOnStartupSetting == null) {
activeOnStartupSetting = beanContext.getActivationProperties().get("DeliveryActive");
}
if (activeOnStartupSetting != null) {
activeOnStartup = Boolean.parseBoolean(activeOnStartupSetting);
}
if (activeOnStartup) {
activationContext.start();
} else {
logger.info("Not auto-activating endpoint for " + beanContext.getDeploymentID());
}
String jmxControlName = beanContext.getActivationProperties().get("MdbJMXControl");
if (jmxControlName == null) {
jmxControlName = "true";
}
addJMxControl(beanContext, jmxControlName, activationContext);
} catch (final ResourceException e) {
throw new OpenEJBException(e);
}
final Options options = new Options(beanContext.getProperties());
// Finally, fill the pool and start it
if (!options.get("BackgroundStartup", false) && min > 0) {
final ExecutorService es = Executors.newFixedThreadPool(min);
for (int i = 0; i < min; i++) {
es.submit(new InstanceCreatorRunnable(maxAge, i, min, maxAgeOffset, data, supplier));
}
es.shutdown();
try {
es.awaitTermination(5, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
logger.error("can't fill the message driven bean pool", e);
}
}
// register the pool
try {
final ObjectName objectName = jmxName.set("j2eeType", "Pool").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(data.pool), objectName);
data.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
data.getPool().start();
}
use of javax.resource.ResourceException in project tomee by apache.
the class MdbContainer method deploy.
public void deploy(final BeanContext beanContext) throws OpenEJBException {
final Object deploymentId = beanContext.getDeploymentID();
if (!beanContext.getMdbInterface().equals(messageListenerInterface)) {
throw new OpenEJBException("Deployment '" + deploymentId + "' has message listener interface " + beanContext.getMdbInterface().getName() + " but this MDB container only supports " + messageListenerInterface);
}
// create the activation spec
final ActivationSpec activationSpec = createActivationSpec(beanContext);
if (inboundRecovery != null) {
inboundRecovery.recover(resourceAdapter, activationSpec, containerID.toString());
}
final Options options = new Options(beanContext.getProperties());
final int instanceLimit = options.get("InstanceLimit", this.instanceLimit);
// create the message endpoint
final MdbInstanceFactory instanceFactory = new MdbInstanceFactory(beanContext, securityService, instanceLimit);
final EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, beanContext, instanceFactory, null, xaResourceWrapper, false);
// update the data structures
// this must be done before activating the endpoint since the ra may immedately begin delivering messages
beanContext.setContainer(this);
beanContext.setContainerData(endpointFactory);
deployments.put(deploymentId, beanContext);
final MBeanServer server = LocalMBeanServer.get();
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("MessageDrivenBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
// register the invocation stats interceptor
try {
final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
endpointFactory.jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
// Expose InstanceLimit/InstanceCount stats through JMX
{
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("MessageDrivenBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
try {
final ObjectName objectName = jmxName.set("j2eeType", "Instances").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(new InstanceMonitor(instanceFactory)), objectName);
endpointFactory.jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
// activate the endpoint
CURRENT.set(beanContext);
try {
final MdbActivationContext activationContext = new MdbActivationContext(Thread.currentThread().getContextClassLoader(), beanContext, resourceAdapter, endpointFactory, activationSpec);
activationContexts.put(beanContext, activationContext);
boolean activeOnStartup = true;
String activeOnStartupSetting = beanContext.getActivationProperties().get("MdbActiveOnStartup");
if (activeOnStartupSetting == null) {
activeOnStartupSetting = beanContext.getActivationProperties().get("DeliveryActive");
}
if (activeOnStartupSetting != null) {
activeOnStartup = Boolean.parseBoolean(activeOnStartupSetting);
}
if (activeOnStartup) {
activationContext.start();
} else {
logger.info("Not auto-activating endpoint for " + beanContext.getDeploymentID());
}
String jmxName = beanContext.getActivationProperties().get("MdbJMXControl");
if (jmxName == null) {
jmxName = "true";
}
addJMxControl(beanContext, jmxName, activationContext);
} catch (final ResourceException e) {
// activation failed... clean up
beanContext.setContainer(null);
beanContext.setContainerData(null);
deployments.remove(deploymentId);
throw new OpenEJBException(e);
} finally {
CURRENT.remove();
}
}
use of javax.resource.ResourceException in project tomee by apache.
the class AutoConnectionTracker method proxyConnection.
private void proxyConnection(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo) throws ResourceException {
// no-op if we have opted to not use proxies
if (connectionInfo.getConnectionProxy() != null) {
return;
}
// DissociatableManagedConnection do not need to be proxied
if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection) {
return;
}
try {
final Object handle = connectionInfo.getConnectionHandle();
final ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(handle);
final Object proxy = newProxy(handle, invocationHandler);
connectionInfo.setConnectionProxy(proxy);
final ProxyPhantomReference reference = new ProxyPhantomReference(interceptor, connectionInfo.getManagedConnectionInfo(), invocationHandler, referenceQueue);
references.put(connectionInfo.getManagedConnectionInfo(), reference);
} catch (final Throwable e) {
throw new ResourceException("Unable to construct connection proxy", e);
}
}
use of javax.resource.ResourceException in project geode by apache.
the class JCALocalTransaction method begin.
@Override
public void begin() throws ResourceException {
try {
if (!this.initDone || this.cache.isClosed()) {
this.init();
}
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction::begin:");
}
TransactionManager tm = this.cache.getJTATransactionManager();
if (this.tid != null) {
throw new LocalTransactionException(" A transaction is already in progress");
}
if (tm != null && tm.getTransaction() != null) {
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection: JTA transaction is on");
}
// This is having a JTA transaction. Assuming ignore jta flag is true,
// explicitly being a gemfire transaction.
TXStateProxy tsp = this.gfTxMgr.getTXState();
if (tsp == null) {
this.gfTxMgr.begin();
tsp = this.gfTxMgr.getTXState();
tsp.setJCATransaction();
this.tid = tsp.getTransactionId();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction:begun GFE transaction");
}
} else {
throw new LocalTransactionException("GemFire is already associated with a transaction");
}
} else {
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection: JTA Transaction does not exist.");
}
}
} catch (SystemException e) {
throw new ResourceException(e);
}
}
Aggregations