public class OSGiManagedRuntime extends AbstractManagedRuntime
Implementation of the ManagedRuntime
interface that listens
for an OSGi service with interface javax.transaction.TransactionManager
to create a TransactionManager
for controlling transactions.
The support for a transaction manager is usually activated inside an OSGi
BundleActivator
implementation using registerServiceListener(BundleContext)
and deregisterServiceListener(BundleContext)
.
Constructor and Description |
---|
OSGiManagedRuntime() |
Modifier and Type | Method and Description |
---|---|
static void |
deregisterServiceListener(org.osgi.framework.BundleContext bundleContext)
Remove a service listener previously started inside
registerServiceListener(BundleContext) . |
Throwable |
getRollbackCause()
Returns the Throwable that caused the current transaction to be
marked for rollback, provided that any exists.
|
TransactionManager |
getTransactionManager()
Return the TransactionManager for the managed runtime.
|
static void |
registerServiceListener(org.osgi.framework.BundleContext bundleContext)
Register a service listener to the given bundle context by
BundleContext.addServiceListener(ServiceListener,String) with a filter
expression of (objectClass=javax.transaction.TransactionManager) . |
void |
setRollbackOnly(Throwable cause)
Sets the rollback only flag on the current transaction.
|
doNonTransactionalWork, getTransactionKey
public static void registerServiceListener(org.osgi.framework.BundleContext bundleContext) throws org.osgi.framework.InvalidSyntaxException
Register a service listener to the given bundle context by
BundleContext.addServiceListener(ServiceListener,String)
with a filter
expression of (objectClass=javax.transaction.TransactionManager)
.
The caller is responsible for calling
deregisterServiceListener(BundleContext)
, when
the bundle context is being stopped.
bundle
- The bundle, which is currently being started.org.osgi.framework.InvalidSyntaxException
- When the filter expression is invalid.public static void deregisterServiceListener(org.osgi.framework.BundleContext bundleContext)
registerServiceListener(BundleContext)
.bundleContext
- The bundle context to call
BundleContext.removeServiceListener(ServiceListener)
on.public TransactionManager getTransactionManager() throws Exception
ManagedRuntime
Exception
public void setRollbackOnly(Throwable cause) throws Exception
ManagedRuntime
cause
- the Throwable that caused the transaction to be
marked for rollback, or null of none is knownException
public Throwable getRollbackCause() throws Exception
ManagedRuntime
Exception
Copyright © 2006–2017 Apache Software Foundation. All rights reserved.