Permalink
Browse files

complete operation handler;

add global module api;
switch function first step;
some code fix;
  • Loading branch information...
1 parent 1804792 commit d1dccc0620161800cb07cbe628334993145ab883 Jason committed Mar 17, 2012
Showing with 402 additions and 39 deletions.
  1. +8 −1 README.md
  2. +63 −5 aejb-subsystem/src/main/java/org/nju/artemis/aejb/component/AcContainer.java
  3. +0 −1 aejb-subsystem/src/main/java/org/nju/artemis/aejb/component/ContainerInvocationHandler.java
  4. +5 −2 aejb-subsystem/src/main/java/org/nju/artemis/aejb/component/interceptors/DispatcherInterceptor.java
  5. +2 −2 ...system/src/main/java/org/nju/artemis/aejb/component/interceptors/InvocationFilterInterceptor.java
  6. +40 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/component/interceptors/SwitchInterceptor.java
  7. +2 −1 ...n/java/org/nju/artemis/aejb/deployment/processors/AnnotatedAEJBComponentDescriptionProcessor.java
  8. +3 −3 aejb-subsystem/src/main/java/org/nju/artemis/aejb/deployment/transaction/TransactionManagerImpl.java
  9. +1 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/DuService.java
  10. +23 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/OperationContext.java
  11. +28 −9 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/behaviors/ComponentLocker.java
  12. +57 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/behaviors/ComponentSwitcher.java
  13. +7 −4 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/behaviors/EvolutionBehavior.java
  14. +10 −3 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/handlers/DependencyHandler.java
  15. +23 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/handlers/InterceptorSwitchHandler.java
  16. +80 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/handlers/InterfaceIdentifyHandler.java
  17. +28 −0 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/handlers/OperationAlterHandler.java
  18. +9 −2 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/handlers/OperationStepHandler.java
  19. +12 −3 aejb-subsystem/src/main/java/org/nju/artemis/aejb/evolution/handlers/StatusShiftHandler.java
  20. +1 −3 aejb-subsystem/src/main/java/org/nju/artemis/aejb/management/client/AEjbClientImpl.java
View
@@ -63,7 +63,14 @@ Add subsystem:
<subsystem xmlns="urn:org.nju.artemis.aejb:1.0">
<client-service jndi-name="java:global/aejb/client"/>
</subsystem>
-
+
+Add global module:
+ <subsystem xmlns="urn:jboss:domain:ee:1.0">
+ <global-modules>
+ <module name="org.nju.artemis.api" slot="main"/>
+ </global-modules>
+ </subsystem>
+
Server Manager
----------------------------
Change to the bin directory after JBoss start
@@ -1,6 +1,7 @@
package org.nju.artemis.aejb.component;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -9,6 +10,7 @@
import org.jboss.logging.Logger;
import org.nju.artemis.aejb.component.interceptors.DispatcherInterceptor;
import org.nju.artemis.aejb.component.interceptors.InvocationFilterInterceptor;
+import org.nju.artemis.aejb.component.interceptors.SwitchInterceptor;
import org.nju.artemis.aejb.deployment.processors.TransactionManager;
import org.nju.artemis.aejb.management.client.AEjbClientImpl.AEjbStatus;
@@ -22,25 +24,45 @@
private final String aejbName;
private final String moduleName;
private final String beanName;
+ private final String distinctName;
private final SessionBeanType beanType;
//Invocation interceptors
private List<Interceptor> interceptors;
- private Map<String, AEjbStatus> aejbStatus;
+ private Map<String, AEjbStatus> aejbStatus = new HashMap<String, AEjbStatus>();
private List<Listener<Map<String, AEjbStatus>>> aejbStatusListeners;
private List<String> depndencies;
+ //transaction manager
+ private TransactionManager transactionManager;
+ //view
+ private Class<?> localView, remoteView;
+ //switch map
+ private Map<String, AcContainer> switchMap = new HashMap<String, AcContainer>();
- public AcContainer(String appName, String moduleName, String beanName, SessionBeanType beanType) {
+ public AcContainer(String appName, String moduleName, String beanName, String distinctName, SessionBeanType beanType) {
this.appName = appName;
this.moduleName = moduleName;
this.beanName = beanName;
this.aejbName = moduleName + "/" + beanName;
+ this.distinctName = distinctName;
this.beanType = beanType;
}
public String getAEJBName() {
return aejbName;
}
+ public String getBeanName() {
+ return beanName;
+ }
+
+ public String getDistinctName() {
+ return distinctName;
+ }
+
+ public SessionBeanType getBeanType() {
+ return beanType;
+ }
+
public String getApplicationName() {
return appName;
}
@@ -53,6 +75,7 @@ public void start() {
aejbStatusListeners = new ArrayList<Listener<Map<String, AEjbStatus>>>();
// Initialize interceptors
interceptors = new ArrayList<Interceptor>();
+ interceptors.add(new SwitchInterceptor(this));
interceptors.add(new InvocationFilterInterceptor(this));
interceptors.add(new DispatcherInterceptor());
@@ -61,6 +84,10 @@ public void start() {
public void stop() {
interceptors = null;
+ aejbStatus.clear();
+ aejbStatus = null;
+ switchMap.clear();
+ switchMap = null;
log.info("Stop AcContainer, AEJBName = " + aejbName);
}
@@ -70,14 +97,13 @@ public void stop() {
}
public void setAEjbStatus(Map<String, AEjbStatus> aejbStatus) {
- this.aejbStatus = aejbStatus;
+ this.aejbStatus.putAll(aejbStatus);
for(Listener<Map<String, AEjbStatus>> aejbStatusListener:aejbStatusListeners) {
aejbStatusListener.transition(aejbStatus);
}
}
public void setAEjbStatus(String name, AEjbStatus aejbStatus) {
- this.aejbStatus.clear();
this.aejbStatus.put(name, aejbStatus);
for(Listener<Map<String, AEjbStatus>> aejbStatusListener:aejbStatusListeners) {
aejbStatusListener.transition(this.aejbStatus);
@@ -103,6 +129,38 @@ public void addDepndencies(String aejbName) {
}
public void setTransactionManager(TransactionManager tm) {
-
+ transactionManager = tm;
+ }
+
+ public TransactionManager getTransactionManager() {
+ return transactionManager;
+ }
+
+ public Class<?> getLocalView() {
+ return localView;
+ }
+
+ public void setLocalView(Class<?> localView) {
+ this.localView = localView;
+ }
+
+ public Class<?> getRemoteView() {
+ return remoteView;
+ }
+
+ public void setRemoteView(Class<?> remoteView) {
+ this.remoteView = remoteView;
+ }
+
+ public Map<String, AcContainer> getSwitchMap() {
+ return switchMap;
+ }
+
+ public void setSwitchMap(Map<String, AcContainer> switchMap) {
+ this.switchMap.putAll(switchMap);
+ }
+
+ public void addSwitchMap(String from, AcContainer toContainer) {
+ this.switchMap.put(from, toContainer);
}
}
@@ -14,7 +14,6 @@
* @author <a href="wangjue1199@gmail.com">Jason</a>
*/
public class ContainerInvocationHandler implements InvocationHandler {
-
Logger log = Logger.getLogger(ContainerInvocationHandler.class);
private final Map<String,Object> contextData;
@@ -12,15 +12,18 @@
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
+import org.jboss.logging.Logger;
/**
* @author <a href="wangjue1199@gmail.com">Jason</a>
*/
public class DispatcherInterceptor implements Interceptor {
-
+ Logger log = Logger.getLogger(DispatcherInterceptor.class);
private Map<String,Object> contextData;
+
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
+ log.info("DispatcherInterceptor: processInvocation");
contextData = context.getContextData();
String appName = (String) contextData.get("appName");
String moduleName = (String) contextData.get("moduleName");
@@ -35,7 +38,7 @@ public Object processInvocation(InterceptorContext context) throws Exception {
private Object dispatch(InterceptorContext context, String appName, String moduleName, String distinctName, String beanName, Class<?> viewClass, boolean stateful){
EJBLocator ejbLocator = null;
Object result = null;
- final String proxyName = "Proxy:"+appName+moduleName+beanName+distinctName;
+ final String proxyName = "Proxy:" + appName + moduleName + beanName + distinctName;
if(contextData.containsKey(proxyName)) {
final Proxy proxy = (Proxy) contextData.get(proxyName);
try {
@@ -14,7 +14,7 @@
*/
public class InvocationFilterInterceptor implements Interceptor {
Logger log = Logger.getLogger(InvocationFilterInterceptor.class);
- private AcContainer container;
+ private final AcContainer container;
private final InvocationManager manager;
public InvocationFilterInterceptor(AcContainer container) {
@@ -25,9 +25,9 @@ public InvocationFilterInterceptor(AcContainer container) {
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
+ log.info("InvocationFilterInterceptor: processInvocation");
final String targetAEjbName = (String) context.getContextData().get("aejbName");
final Map<String, AEjbStatus> status = container.getAEjbStatus();
- if(status !=null)
if(status != null && AEjbStatus.BLOCKING == status.get(targetAEjbName)) {
manager.blockInvocation(context, targetAEjbName);
}
@@ -0,0 +1,40 @@
+package org.nju.artemis.aejb.component.interceptors;
+
+import java.util.Map;
+
+import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription.SessionBeanType;
+import org.jboss.invocation.Interceptor;
+import org.jboss.invocation.InterceptorContext;
+import org.jboss.logging.Logger;
+import org.nju.artemis.aejb.component.AcContainer;
+
+/**
+ * @author <a href="mailto:wangjue1199@gmail.com">Jason</a>
+ */
+public class SwitchInterceptor implements Interceptor {
+ Logger log = Logger.getLogger(SwitchInterceptor.class);
+ private final AcContainer container;
+
+ public SwitchInterceptor(AcContainer container) {
+ this.container = container;
+ }
+
+ @Override
+ public Object processInvocation(InterceptorContext context) throws Exception {
+ log.info("SwitchInterceptor: SwitchInterceptor");
+ Map<String,Object> contextData = context.getContextData();
+ String aejbName = (String) contextData.get("aejbName");
+ AcContainer con = container.getSwitchMap().get(aejbName);
+ if(con != null && !con.getAEJBName().equals(aejbName)) {
+ contextData.put("appName", con.getApplicationName());
+ contextData.put("moduleName", con.getModuleName());
+ contextData.put("beanName", con.getBeanName());
+ contextData.put("distinctName", con.getDistinctName());
+ contextData.put("aejbName", con.getAEJBName());
+ contextData.put("viewClass", con.getRemoteView() == null ? con.getRemoteView() : con.getLocalView());
+ contextData.put("stateful", con.getBeanType() == SessionBeanType.STATEFUL);
+ }
+ return context.proceed();
+ }
+
+}
@@ -78,9 +78,10 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
String appName = sessionBeanDescription.getApplicationName();
String moduleName = sessionBeanDescription.getModuleName();
String beanName = sessionBeanDescription.getEJBName();
+ String distinctName = "";
SessionBeanType beanType = sessionBeanDescription.getSessionBeanType();
- AcContainer accon = new AcContainer(appName, moduleName, beanName, beanType);
+ AcContainer accon = new AcContainer(appName, moduleName, beanName, distinctName, beanType);
AEjbUtilities.registerAEJB(unitName, accon);
aejbInfo.put(beanClass, accon);
}
@@ -90,10 +90,10 @@ public boolean isActive() {
*/
public void trigger(String objectId, String eventName) {
synchronized ($transactions) {
+ if(!$transactions.containsKey(objectId))
+ createTransaction(objectId);
Transaction tran = $transactions.get(objectId);
- if (tran != null) {
- tran.trigger(eventName);
- }
+ tran.trigger(eventName);
}
}
@@ -67,6 +67,7 @@ public void start(StartContext context) throws StartException {
}
private void manageAEjbState(Map<String, AEjbStatus> aejbStatus) {
+ // simple
getAEjbUtilities().setAEjbStatus(aejbStatus);
}
@@ -8,9 +8,32 @@
*/
public class OperationContext {
+ private String operationName;
+ private String targetName;
private Map<Object, Object> contextData = new HashMap<Object, Object>();
+ public OperationContext(String operationName, String targetName) {
+ this.operationName = operationName;
+ this.targetName = targetName;
+ }
+
public Map<Object, Object> getContextData() {
return contextData;
}
+
+ public String getOperationName() {
+ return operationName;
+ }
+
+ public void setOperationName(String operationName) {
+ this.operationName = operationName;
+ }
+
+ public String getTargetName() {
+ return targetName;
+ }
+
+ public void setTargetName(String targetName) {
+ this.targetName = targetName;
+ }
}
@@ -11,31 +11,30 @@
* @author <a href="wangjue1199@gmail.com">Jason</a>
*/
public class ComponentLocker extends EvolutionBehavior{
-
+ private static final String HANDLER_NAME = "ComponentLocker";
+ static final String LOCK = "lock";
+ static final String UNLOCK = "unlock";
private String aejbName;
private AEjbUtilities utilities;
private AEjbStatus status;
- public ComponentLocker(AEjbUtilities utilities) {
- this.utilities = utilities;
- }
-
- public void lock(String aejbName) throws OperationFailedException {
+ private void lock(String aejbName) throws OperationFailedException {
this.aejbName = aejbName;
this.status = AEjbStatus.BLOCKING;
+
perform();
}
- public void unlock(String aejbName) throws OperationFailedException {
+ private void unlock(String aejbName) throws OperationFailedException {
this.aejbName = aejbName;
this.status = AEjbStatus.RESUMING;
+
perform();
}
@Override
protected OperationContext generateOperationContext() {
- OperationContext context = new OperationContext();
- context.getContextData().put("targetName", aejbName);
+ OperationContext context = new OperationContext(null, aejbName);
context.getContextData().put(AEjbUtilities.class, utilities);
context.getContextData().put(AEjbStatus.class, status);
return context;
@@ -46,4 +45,24 @@ protected void initializeStepHandlers() {
handlers.add(new DependencyHandler());
handlers.add(new StatusShiftHandler());
}
+
+ @Override
+ public OperationResult execute(OperationContext context) throws OperationFailedException {
+ String operationName = context.getOperationName();
+ utilities = (AEjbUtilities) context.getContextData().get(AEjbUtilities.class);
+
+ if(LOCK.equals(operationName)) {
+ lock(context.getTargetName());
+ } else if(UNLOCK.equals(operationName)) {
+ unlock(context.getTargetName());
+ } else
+ throw new OperationFailedException("operation name: " + operationName + " has not been defined.");
+
+ return OperationResult.Expected;
+ }
+
+ @Override
+ public String getHandlerName() {
+ return HANDLER_NAME;
+ }
}
Oops, something went wrong.

0 comments on commit d1dccc0

Please sign in to comment.