use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class EjbIIOPService method start.
@Override
public synchronized void start(final StartContext startContext) throws StartException {
try {
final RiverMarshallerFactory factory = new RiverMarshallerFactory();
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setClassResolver(new FilteringClassResolver(ModularClassResolver.getInstance(serviceModuleLoaderInjectedValue.getValue())));
this.configuration = configuration;
this.factory = factory;
final TransactionManager jtsTransactionManager = transactionManagerInjectedValue.getValue().getTransactionManager();
assert !(jtsTransactionManager instanceof ContextTransactionManager);
// Should create a CORBA interface repository?
final boolean interfaceRepositorySupported = false;
// Build binding name of the bean.
final EJBComponent component = ejbComponentInjectedValue.getValue();
final String earApplicationName = component.getEarApplicationName();
if (iiopMetaData != null && iiopMetaData.getBindingName() != null) {
name = iiopMetaData.getBindingName();
} else if (useQualifiedName) {
if (component.getDistinctName() == null || component.getDistinctName().isEmpty()) {
name = earApplicationName == null || earApplicationName.isEmpty() ? "" : earApplicationName + "/";
name = name + component.getModuleName() + "/" + component.getComponentName();
} else {
name = earApplicationName == null || earApplicationName.isEmpty() ? "" : earApplicationName + "/";
name = name + component.getModuleName() + "/" + component.getDistinctName() + "/" + component.getComponentName();
}
} else {
name = component.getComponentName();
}
name = name.replace(".", "_");
EjbLogger.DEPLOYMENT_LOGGER.iiopBindings(component.getComponentName(), component.getModuleName(), name);
final ORB orb = this.orb.getValue();
if (interfaceRepositorySupported) {
// Create a CORBA interface repository for the enterprise bean
iri = new InterfaceRepository(orb, irPoa.getValue(), name);
// Add bean interface info to the interface repository
iri.mapClass(remoteView.getValue().getViewClass());
iri.mapClass(homeView.getValue().getViewClass());
iri.finishBuild();
EjbLogger.ROOT_LOGGER.cobraInterfaceRepository(name, orb.object_to_string(iri.getReference()));
}
IORSecurityConfigMetaData iorSecurityConfigMetaData = this.iorSecConfigMetaData.getOptionalValue();
if (this.iiopMetaData != null && this.iiopMetaData.getIorSecurityConfigMetaData() != null)
iorSecurityConfigMetaData = this.iiopMetaData.getIorSecurityConfigMetaData();
// Create security policies if security metadata has been provided.
List<Policy> policyList = new ArrayList<Policy>();
if (iorSecurityConfigMetaData != null) {
// Create csiv2Policy for both home and remote containing IorSecurityConfigMetadata.
final Any secPolicy = orb.create_any();
secPolicy.insert_Value(iorSecurityConfigMetaData);
Policy csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy);
policyList.add(csiv2Policy);
// Add ZeroPortPolicy if ssl is required (it ensures home and remote IORs will have port 0 in the primary address).
boolean sslRequired = false;
if (iorSecurityConfigMetaData != null && iorSecurityConfigMetaData.getTransportConfig() != null) {
IORTransportConfigMetaData tc = iorSecurityConfigMetaData.getTransportConfig();
sslRequired = IORTransportConfigMetaData.INTEGRITY_REQUIRED.equals(tc.getIntegrity()) || IORTransportConfigMetaData.CONFIDENTIALITY_REQUIRED.equals(tc.getConfidentiality()) || IORTransportConfigMetaData.ESTABLISH_TRUST_IN_CLIENT_REQUIRED.equals(tc.getEstablishTrustInClient());
}
if (sslRequired) {
policyList.add(ZeroPortPolicy.getPolicy());
}
}
// TODO: what should this default to
String securityDomainName = "CORBA_REMOTE";
if (component.getSecurityMetaData() != null) {
securityDomainName = component.getSecurityMetaData().getSecurityDomainName();
}
Policy[] policies = policyList.toArray(new Policy[policyList.size()]);
// If there is an interface repository, then get the homeInterfaceDef from the IR
InterfaceDef homeInterfaceDef = null;
if (iri != null) {
Repository ir = iri.getReference();
homeInterfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(homeRepositoryIds[0]));
}
// Get the POACurrent object
Current poaCurrent = CurrentHelper.narrow(orb.resolve_initial_references("POACurrent"));
// Instantiate home servant, bind it to the servant registry, and create CORBA reference to the EJBHome.
final EjbCorbaServant homeServant = new EjbCorbaServant(poaCurrent, homeMethodMap, homeRepositoryIds, homeInterfaceDef, orb, homeView.getValue(), factory, configuration, jtsTransactionManager, module.getClassLoader(), true, securityDomainName, component.getSecurityDomain());
homeServantRegistry = poaRegistry.getValue().getRegistryWithPersistentPOAPerServant();
ReferenceFactory homeReferenceFactory = homeServantRegistry.bind(homeServantName(name), homeServant, policies);
final org.omg.CORBA.Object corbaRef = homeReferenceFactory.createReference(homeRepositoryIds[0]);
// we do this twice to force eager dynamic stub creation
ejbHome = (EJBHome) PortableRemoteObject.narrow(corbaRef, EJBHome.class);
final HomeHandleImplIIOP homeHandle = new HomeHandleImplIIOP(orb.object_to_string(corbaRef));
homeServant.setHomeHandle(homeHandle);
// Initialize beanPOA and create metadata
// This is a session bean (lifespan: transient)
beanServantRegistry = poaRegistry.getValue().getRegistryWithTransientPOAPerServant();
if (component instanceof StatelessSessionComponent) {
// Stateless session bean
ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, true, homeHandle);
} else {
// Stateful session bean
ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, false, homeHandle);
}
homeServant.setEjbMetaData(ejbMetaData);
// If there is an interface repository, then get the beanInterfaceDef from the IR
InterfaceDef beanInterfaceDef = null;
if (iri != null) {
final Repository ir = iri.getReference();
beanInterfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(beanRepositoryIds[0]));
}
// Instantiate the ejb object servant and bind it to the servant registry.
final EjbCorbaServant beanServant = new EjbCorbaServant(poaCurrent, beanMethodMap, beanRepositoryIds, beanInterfaceDef, orb, remoteView.getValue(), factory, configuration, jtsTransactionManager, module.getClassLoader(), false, securityDomainName, component.getSecurityDomain());
beanReferenceFactory = beanServantRegistry.bind(beanServantName(name), beanServant, policies);
// Register bean home in local CORBA naming context
rebind(corbaNamingContext.getValue(), name, corbaRef);
EjbLogger.ROOT_LOGGER.debugf("Home IOR for %s bound to %s in CORBA naming service", component.getComponentName(), this.name);
// now eagerly force stub creation, so de-serialization of stubs will work correctly
final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
try {
DynamicStubFactoryFactory.makeStubClass(homeView.getValue().getViewClass());
} catch (Exception e) {
EjbLogger.ROOT_LOGGER.dynamicStubCreationFailed(homeView.getValue().getViewClass().getName(), e);
}
try {
DynamicStubFactoryFactory.makeStubClass(remoteView.getValue().getViewClass());
} catch (Exception e) {
EjbLogger.ROOT_LOGGER.dynamicStubCreationFailed(remoteView.getValue().getViewClass().getName(), e);
}
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
}
} catch (Exception e) {
throw new StartException(e);
}
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class TimerServiceImpl method getActivePersistentTimers.
private List<TimerImpl> getActivePersistentTimers() {
// we need only those timers which correspond to the
// timed object invoker to which this timer service belongs. So
// first get hold of the timed object id
final String timedObjectId = this.getInvoker().getTimedObjectId();
// timer states which do *not* represent an active timer
if (timerPersistence.getOptionalValue() == null) {
// if the persistence setting is null then there are no persistent timers
return Collections.emptyList();
}
final ContextTransactionManager transactionManager = ContextTransactionManager.getInstance();
List<TimerImpl> persistedTimers;
try {
transactionManager.begin();
persistedTimers = timerPersistence.getValue().loadActiveTimers(timedObjectId, this);
transactionManager.commit();
} catch (Exception e) {
try {
transactionManager.rollback();
} catch (Exception ee) {
// omit;
}
persistedTimers = Collections.emptyList();
EJB3_TIMER_LOGGER.timerReinstatementFailed(timedObjectId, "unavailable", e);
}
final List<TimerImpl> activeTimers = new ArrayList<TimerImpl>();
for (final TimerImpl persistedTimer : persistedTimers) {
if (TimerState.EXPIRED_CANCELED.contains(persistedTimer.getState())) {
continue;
}
// add it to the list of timers which will be restored
activeTimers.add(persistedTimer);
}
return activeTimers;
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class TimerServiceImpl method persistTimer.
/**
* Persists the passed <code>timer</code>.
* <p/>
* <p>
* If the passed timer is null or is non-persistent (i.e. {@link javax.ejb.Timer#isPersistent()} returns false),
* then this method acts as a no-op
* </p>
*
* @param timer
*/
public void persistTimer(final TimerImpl timer, boolean newTimer) {
if (timer == null) {
return;
}
if (timer.persistent) {
try {
if (timerPersistence.getOptionalValue() == null) {
EJB3_TIMER_LOGGER.timerPersistenceNotEnable();
return;
}
final ContextTransactionManager transactionManager = ContextTransactionManager.getInstance();
Transaction clientTX = transactionManager.getTransaction();
if (newTimer || timer.isCanceled()) {
if (clientTX == null) {
transactionManager.begin();
}
try {
if (newTimer)
timerPersistence.getValue().addTimer(timer);
else
timerPersistence.getValue().persistTimer(timer);
if (clientTX == null)
transactionManager.commit();
} catch (Exception e) {
if (clientTX == null) {
try {
transactionManager.rollback();
} catch (Exception ee) {
EjbLogger.EJB3_TIMER_LOGGER.timerUpdateFailedAndRollbackNotPossible(ee);
}
}
throw e;
}
} else {
new TaskPostPersist(timer).persistTimer();
}
} catch (Throwable t) {
this.setRollbackOnly();
throw new RuntimeException(t);
}
}
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class DatabaseTimerPersistence method shouldRun.
@Override
public boolean shouldRun(TimerImpl timer) {
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
if (!allowExecution) {
// timers never execute on this node
return false;
}
String loadTimer = sql.getProperty(UPDATE_RUNNING);
Connection connection = null;
PreparedStatement statement = null;
try {
tm.begin();
try {
connection = dataSource.getConnection();
statement = connection.prepareStatement(loadTimer);
statement.setString(1, TimerState.IN_TIMEOUT.name());
setNodeName(TimerState.IN_TIMEOUT, statement, 2);
statement.setString(3, timer.getId());
statement.setString(4, TimerState.IN_TIMEOUT.name());
statement.setString(5, TimerState.RETRY_TIMEOUT.name());
if (timer.getNextExpiration() == null) {
statement.setTimestamp(6, null);
} else {
statement.setTimestamp(6, timestamp(timer.getNextExpiration()));
}
} catch (SQLException e) {
try {
tm.rollback();
} catch (Exception ee) {
EjbLogger.EJB3_TIMER_LOGGER.timerUpdateFailedAndRollbackNotPossible(ee);
}
// fix for WFLY-10130
EjbLogger.EJB3_TIMER_LOGGER.exceptionCheckingIfTimerShouldRun(timer, e);
return false;
}
int affected = statement.executeUpdate();
tm.commit();
return affected == 1;
} catch (SQLException | SystemException | SecurityException | IllegalStateException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
// failed to update the DB
try {
tm.rollback();
} catch (IllegalStateException | SecurityException | SystemException rbe) {
EjbLogger.EJB3_TIMER_LOGGER.timerUpdateFailedAndRollbackNotPossible(rbe);
}
EjbLogger.EJB3_TIMER_LOGGER.debugf(e, "Timer %s not running due to exception ", timer);
return false;
} catch (NotSupportedException e) {
// happen from tm.begin, no rollback necessary
EjbLogger.EJB3_TIMER_LOGGER.timerNotRunning(e, timer);
return false;
} finally {
safeClose(statement);
safeClose(connection);
}
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class CMTTxInterceptor method required.
protected Object required(final InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception {
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
if (timeout != -1) {
tm.setTransactionTimeout(timeout);
}
final Transaction tx = tm.getTransaction();
if (tx == null) {
if (invocation.hasTransaction()) {
return invokeInImportedTx(invocation, component);
}
return invokeInOurTx(invocation, component);
} else {
return invokeInCallerTx(invocation, tx, component);
}
}
Aggregations