You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2004/06/12 20:43:31 UTC
cvs commit: incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector AdminObjectWrapperTest.java BootstrapContextTest.java
djencks 2004/06/12 11:43:31
Modified: modules/connector/src/java/org/apache/geronimo/connector
AdminObjectWrapper.java BootstrapContext.java
ConnectorMethodInterceptor.java
ResourceAdapterWrapper.java
modules/connector/src/java/org/apache/geronimo/connector/deployment
RAR_1_5ConfigBuilder.java
modules/connector/src/java/org/apache/geronimo/connector/outbound
GenericConnectionManager.java
ManagedConnectionFactoryWrapper.java
modules/connector/src/test/org/apache/geronimo/connector
AdminObjectWrapperTest.java
BootstrapContextTest.java
Log:
Cleanup: use special properties, add javadoc, fix checkstyle complaints
Revision Changes Path
1.10 +80 -15 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java
Index: AdminObjectWrapper.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AdminObjectWrapper.java 5 Jun 2004 07:53:21 -0000 1.9
+++ AdminObjectWrapper.java 12 Jun 2004 18:43:31 -0000 1.10
@@ -31,63 +31,97 @@
import org.apache.geronimo.kernel.Kernel;
/**
+ * Wrapper around AdminObject that exposes its config-properties as GBeanAttributes and
+ * supplies a disconnectable proxy to bind in jndi.
+ *
* @version $Revision$ $Date$
*/
public class AdminObjectWrapper implements GBeanLifecycle, DynamicGBean {
- public static final GBeanInfo GBEAN_INFO;
-
private final Class adminObjectInterface;
private final Class adminObjectClass;
private final DynamicGBeanDelegate delegate;
private final Object adminObject;
private final Kernel kernel;
- private final ObjectName selfName;
+ private final String objectName;
private ConnectorMethodInterceptor interceptor;
private Object proxy;
- //for use as endpoint
+ /**
+ * Default constructor required when a class is used as a GBean Endpoint.
+ */
public AdminObjectWrapper() {
adminObjectInterface = null;
adminObjectClass = null;
adminObject = null;
delegate = null;
kernel = null;
- selfName = null;
+ objectName = null;
}
- public AdminObjectWrapper(Class adminObjectInterface, Class adminObjectClass, Kernel kernel, ObjectName selfName) throws IllegalAccessException, InstantiationException {
+ /**
+ * Normal managed constructor.
+ *
+ * @param adminObjectInterface Interface the proxy will implement.
+ * @param adminObjectClass Class of admin object to be wrapped.
+ * @param kernel name is used so proxy can find correct kernel.
+ * @param objectName is used by proxy to find this gbean to reconnect to.
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ */
+ public AdminObjectWrapper(final Class adminObjectInterface,
+ final Class adminObjectClass,
+ final Kernel kernel,
+ final String objectName) throws IllegalAccessException, InstantiationException {
this.adminObjectInterface = adminObjectInterface;
this.adminObjectClass = adminObjectClass;
adminObject = adminObjectClass.newInstance();
delegate = new DynamicGBeanDelegate();
delegate.addAll(adminObject);
this.kernel = kernel;
- this.selfName = selfName;
+ this.objectName = objectName;
}
+ /**
+ * Returns class of wrapped AdminObject.
+ * @return class of wrapped AdminObject
+ */
public Class getAdminObjectClass() {
return adminObjectClass;
}
+ /**
+ * Returns disconnectable proxy for binding in jndi.
+ * @return proxy implementing adminObjectInterface.
+ */
public Object getProxy() {
return proxy;
}
+ /**
+ * Returns the MethodInterceptor the proxy communicates with when connected.
+ * @return MethodInterceptor the proxy calls.
+ */
public Object getMethodInterceptor() {
return interceptor;
}
+ /**
+ * GBean start method.
+ * @throws WaitingException
+ * @throws Exception
+ */
public void doStart() throws WaitingException, Exception {
if (proxy == null) {
//build proxy
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(adminObjectInterface);
enhancer.setCallbackType(MethodInterceptor.class);
- enhancer.setUseFactory(false);//????
- interceptor = new ConnectorMethodInterceptor(kernel.getKernelName(), selfName);
+ //TODO is this correct?
+ enhancer.setUseFactory(false);
+ interceptor = new ConnectorMethodInterceptor(kernel.getKernelName(), ObjectName.getInstance(objectName));
enhancer.setCallbacks(new Callback[]{interceptor});
proxy = enhancer.create(new Class[0], new Object[0]);
}
@@ -95,34 +129,65 @@
interceptor.setInternalProxy(adminObject);
}
+ /**
+ * GBean stop method.
+ * @throws WaitingException
+ * @throws Exception
+ */
public void doStop() throws WaitingException, Exception {
//disconnect proxy
interceptor.setInternalProxy(null);
}
+ /**
+ * GBean fail method.
+ */
public void doFail() {
}
//DynamicGBean implementation
- public Object getAttribute(String name) throws Exception {
+
+ /**
+ * Delegating DynamicGBean getAttribute method.
+ * @param name of attribute.
+ * @return attribute value.
+ * @throws Exception
+ */
+ public Object getAttribute(final String name) throws Exception {
return delegate.getAttribute(name);
}
- public void setAttribute(String name, Object value) throws Exception {
+ /**
+ * Delegating DynamicGBean setAttribute method.
+ * @param name of attribute.
+ * @param value of attribute to be set.
+ * @throws Exception
+ */
+ public void setAttribute(final String name, final Object value) throws Exception {
delegate.setAttribute(name, value);
}
- public Object invoke(String name, Object[] arguments, String[] types) throws Exception {
+ /**
+ * no-op DynamicGBean method
+ * @param name
+ * @param arguments
+ * @param types
+ * @return nothing, there are no operations.
+ * @throws Exception
+ */
+ public Object invoke(final String name, final Object[] arguments, final String[] types) throws Exception {
//we have no dynamic operations.
return null;
}
+ public static final GBeanInfo GBEAN_INFO;
+
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory(AdminObjectWrapper.class);
infoFactory.addAttribute("AdminObjectInterface", Class.class, true);
infoFactory.addAttribute("AdminObjectClass", Class.class, true);
infoFactory.addAttribute("kernel", Kernel.class, false);
- infoFactory.addAttribute("SelfName", ObjectName.class, true);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addOperation("getProxy");
infoFactory.addOperation("getMethodInterceptor");
@@ -132,7 +197,7 @@
"AdminObjectInterface",
"AdminObjectClass",
"kernel",
- "SelfName"});
+ "objectName"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.7 +19 -19 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/BootstrapContext.java
Index: BootstrapContext.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/BootstrapContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BootstrapContext.java 2 Jun 2004 05:33:01 -0000 1.6
+++ BootstrapContext.java 12 Jun 2004 18:43:31 -0000 1.7
@@ -27,34 +27,33 @@
import org.apache.geronimo.gbean.GBeanInfoFactory;
/**
+ * GBean BootstrapContext implementation that refers to externally configured WorkManager
+ * and XATerminator gbeans.
+ *
* @version $Revision$ $Date$
*/
public class BootstrapContext implements javax.resource.spi.BootstrapContext {
- private WorkManager workManager;
- private XATerminator xATerminator;
+ private final WorkManager workManager;
+ private final XATerminator xATerminator;
+ /**
+ * Default constructor for use as a GBean Endpoint.
+ */
public BootstrapContext() {
-
- }
-
- public BootstrapContext(WorkManager workManager, XATerminator xaTerminator) {
- this.workManager = workManager;
- this.xATerminator = xaTerminator;
+ workManager = null;
+ xATerminator = null;
}
/**
- * @param workManager The workManager to set.
+ * Normal constructor for use as a GBean.
+ * @param workManager
+ * @param xaTerminator
*/
- public void setWorkManager(WorkManager workManager) {
+ public BootstrapContext(final WorkManager workManager, final XATerminator xaTerminator) {
this.workManager = workManager;
+ this.xATerminator = xaTerminator;
}
- /**
- * @param terminator The xATerminator to set.
- */
- public void setXATerminator(XATerminator terminator) {
- xATerminator = terminator;
- }
/**
* @see javax.resource.spi.BootstrapContext#getWorkManager()
@@ -81,9 +80,9 @@
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory(BootstrapContext.class);
+ //adding interface does not work, creates attributes for references???
+// infoFactory.addInterface(javax.resource.spi.BootstrapContext.class);
- infoFactory.addOperation("getWorkManager");
- infoFactory.addOperation("getXATerminator");
infoFactory.addOperation("createTimer");
infoFactory.addReference("WorkManager", WorkManager.class);
@@ -97,4 +96,5 @@
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
+
}
1.3 +13 -5 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/ConnectorMethodInterceptor.java
Index: ConnectorMethodInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/ConnectorMethodInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConnectorMethodInterceptor.java 30 May 2004 19:03:36 -0000 1.2
+++ ConnectorMethodInterceptor.java 12 Jun 2004 18:43:31 -0000 1.3
@@ -29,7 +29,8 @@
import org.apache.geronimo.kernel.Kernel;
/**
- *
+ * MethodInterceptor used by various Proxies. The important part of this class is the
+ * deserialization in the readResolve method.
*
* @version $Revision$ $Date$
*
@@ -41,22 +42,29 @@
private transient Object internalProxy;
- public ConnectorMethodInterceptor(String kernelName, ObjectName targetName) {
+ public ConnectorMethodInterceptor(final String kernelName, final ObjectName targetName) {
this.kernelName = kernelName;
this.targetName = targetName;
}
- public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
+ public Object intercept(final Object o, final Method method, Object[] objects, final MethodProxy methodProxy) throws Throwable {
if (internalProxy == null) {
throw new IllegalStateException("Proxy is not connected");
}
return methodProxy.invoke(internalProxy, objects);
}
- public void setInternalProxy(Object internalProxy) {
+ public void setInternalProxy(final Object internalProxy) {
this.internalProxy = internalProxy;
}
+ /**
+ * Deserializing readResolve method. This uses the stored kernel name and target object name to
+ * obtain and return the original version of this object that is attached to the actual object of
+ * interest. This allows serialization of resource-refs and resource-env-refs (admin objects).
+ * @return
+ * @throws ObjectStreamException
+ */
private Object readResolve() throws ObjectStreamException {
Kernel kernel = Kernel.getKernel(kernelName);
try {
1.12 +29 -9 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java
Index: ResourceAdapterWrapper.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ResourceAdapterWrapper.java 11 Jun 2004 19:22:04 -0000 1.11
+++ ResourceAdapterWrapper.java 12 Jun 2004 18:43:31 -0000 1.12
@@ -21,7 +21,10 @@
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterAssociation;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapterInternalException;
import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
import org.apache.geronimo.gbean.DynamicGBean;
import org.apache.geronimo.gbean.DynamicGBeanDelegate;
@@ -31,9 +34,12 @@
import org.apache.geronimo.gbean.WaitingException;
/**
+ * Dynamic GBean wrapper around a ResourceAdapter object, exposing the config-properties as
+ * GBean attributes.
+ *
* @version $Revision$ $Date$
*/
-public class ResourceAdapterWrapper implements GBeanLifecycle, DynamicGBean {
+public class ResourceAdapterWrapper implements GBeanLifecycle, DynamicGBean, ResourceAdapter {
public static final GBeanInfo GBEAN_INFO;
@@ -45,7 +51,9 @@
private final DynamicGBeanDelegate delegate;
- //default constructor for enhancement proxy endpoint
+ /**
+ * default constructor for enhancement proxy endpoint
+ */
public ResourceAdapterWrapper() {
this.resourceAdapterClass = null;
this.bootstrapContext = null;
@@ -53,7 +61,7 @@
this.delegate = null;
}
- public ResourceAdapterWrapper(Class resourceAdapterClass, BootstrapContext bootstrapContext) throws InstantiationException, IllegalAccessException {
+ public ResourceAdapterWrapper(final Class resourceAdapterClass, final BootstrapContext bootstrapContext) throws InstantiationException, IllegalAccessException {
this.resourceAdapterClass = resourceAdapterClass;
this.bootstrapContext = bootstrapContext;
resourceAdapter = (ResourceAdapter) resourceAdapterClass.newInstance();
@@ -65,19 +73,31 @@
return resourceAdapterClass;
}
- public void registerManagedConnectionFactory(ResourceAdapterAssociation managedConnectionFactory) throws ResourceException {
+ public void registerManagedConnectionFactory(final ResourceAdapterAssociation managedConnectionFactory) throws ResourceException {
managedConnectionFactory.setResourceAdapter(resourceAdapter);
}
+ public void start(BootstrapContext ctx) throws ResourceAdapterInternalException {
+ throw new IllegalStateException("Don't call this");
+ }
+
+ public void stop() {
+ throw new IllegalStateException("Don't call this");
+ }
+
//endpoint handling
- public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
+ public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec);
}
- public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) {
+ public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec);
}
+ public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException {
+ return resourceAdapter.getXAResources(specs);
+ }
+
public void doStart() throws WaitingException, Exception {
resourceAdapter.start(bootstrapContext);
}
@@ -110,8 +130,8 @@
infoFactory.addReference("BootstrapContext", BootstrapContext.class);
infoFactory.addOperation("registerManagedConnectionFactory", new Class[]{ResourceAdapterAssociation.class});
- infoFactory.addOperation("endpointActivation", new Class[]{MessageEndpointFactory.class, ActivationSpec.class});
- infoFactory.addOperation("endpointDeactivation", new Class[]{MessageEndpointFactory.class, ActivationSpec.class});
+
+ infoFactory.addInterface(ResourceAdapter.class);
infoFactory.setConstructor(new String[]{"ResourceAdapterClass", "BootstrapContext"});
1.18 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilder.java
Index: RAR_1_5ConfigBuilder.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilder.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- RAR_1_5ConfigBuilder.java 8 Jun 2004 17:38:00 -0000 1.17
+++ RAR_1_5ConfigBuilder.java 12 Jun 2004 18:43:31 -0000 1.18
@@ -201,7 +201,7 @@
ObjectName adminObjectObjectName = ObjectName.getInstance(JMXReferenceFactory.BASE_ADMIN_OBJECT_NAME + gerAdminobjectInstance.getAdminobjectName());
adminObjectGBean.setAttribute("AdminObjectInterface", cl.loadClass(adminobject.getAdminobjectInterface().getStringValue()));
adminObjectGBean.setAttribute("AdminObjectClass", cl.loadClass(adminobject.getAdminobjectClass().getStringValue()));
- adminObjectGBean.setAttribute("SelfName", adminObjectObjectName);
+// adminObjectGBean.setAttribute("SelfName", adminObjectObjectName);
context.addGBean(adminObjectObjectName, adminObjectGBean);
} catch (Exception e) {
throw new DeploymentException("Could not construct AdminObject", e);
1.7 +4 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java
Index: GenericConnectionManager.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GenericConnectionManager.java 11 Jun 2004 19:22:04 -0000 1.6
+++ GenericConnectionManager.java 12 Jun 2004 18:43:31 -0000 1.7
@@ -146,18 +146,19 @@
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory(GenericConnectionManager.class, AbstractConnectionManager.GBEAN_INFO);
- infoFactory.addAttribute("ObjectName", String.class, true);
infoFactory.addAttribute("Name", String.class, true);
infoFactory.addAttribute("TransactionSupport", TransactionSupport.class, true);
infoFactory.addAttribute("Pooling", PoolingSupport.class, true);
+ infoFactory.addAttribute("objectName", String.class, false);
+
infoFactory.addReference("ConnectionTracker", ConnectionTracker.class);
infoFactory.addReference("RealmBridge", RealmBridge.class);
infoFactory.setConstructor(new String[]{
"TransactionSupport",
"Pooling",
- "ObjectName",
+ "objectName",
"RealmBridge",
"ConnectionTracker"});
1.16 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java
Index: ManagedConnectionFactoryWrapper.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ManagedConnectionFactoryWrapper.java 11 Jun 2004 19:22:04 -0000 1.15
+++ ManagedConnectionFactoryWrapper.java 12 Jun 2004 18:43:31 -0000 1.16
@@ -258,9 +258,9 @@
infoFactory.addAttribute("ConnectionFactoryImplClass", Class.class, true);
infoFactory.addAttribute("ConnectionInterface", Class.class, true);
infoFactory.addAttribute("ConnectionImplClass", Class.class, true);
- infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addAttribute("GlobalJNDIName", String.class, true);
infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addOperation("getProxy");
infoFactory.addOperation("getMethodInterceptor");
1.3 +1 -2 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/AdminObjectWrapperTest.java
Index: AdminObjectWrapperTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/AdminObjectWrapperTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AdminObjectWrapperTest.java 5 Jun 2004 01:40:09 -0000 1.2
+++ AdminObjectWrapperTest.java 12 Jun 2004 18:43:31 -0000 1.3
@@ -150,7 +150,6 @@
GBeanMBean aow = new GBeanMBean(AdminObjectWrapper.getGBeanInfo());
aow.setAttribute("AdminObjectInterface", MockAdminObject.class);
aow.setAttribute("AdminObjectClass", MockAdminObjectImpl.class);
- aow.setAttribute("SelfName", selfName);
kernel.loadGBean(selfName, aow);
kernel.startGBean(selfName);
1.4 +3 -5 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/BootstrapContextTest.java
Index: BootstrapContextTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/BootstrapContextTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BootstrapContextTest.java 10 Mar 2004 09:58:33 -0000 1.3
+++ BootstrapContextTest.java 12 Jun 2004 18:43:31 -0000 1.4
@@ -41,9 +41,8 @@
* Tests get and set work manager
*/
public void testGetSetWorkManager() {
- BootstrapContext context = new BootstrapContext();
MockWorkManager manager = new MockWorkManager("testGetSetWorkManager");
- context.setWorkManager(manager);
+ BootstrapContext context = new BootstrapContext(manager, null);
WorkManager wm = context.getWorkManager();
assertTrue("Make sure it is the same object", manager.equals(wm));
@@ -53,9 +52,8 @@
* Tests get and set XATerminator
*/
public void testGetSetXATerminator() {
- BootstrapContext context = new BootstrapContext();
MockXATerminator t = new MockXATerminator("testGetSetXATerminator");
- context.setXATerminator(t);
+ BootstrapContext context = new BootstrapContext(null, t);
XATerminator xat = context.getXATerminator();
assertTrue("Make sure it is the same object", t.equals(xat));