Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
OPEN - issue ODE-160: ExtensionActivity and ExtensionAssignOperation:…
Browse files Browse the repository at this point in the history
… Runtime support

http://issues.apache.org/jira/browse/ODE-160

git-svn-id: https://svn.apache.org/repos/asf/ode/trunk@582679 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
vanto committed Oct 7, 2007
1 parent 5ef6923 commit 1e8798c
Show file tree
Hide file tree
Showing 28 changed files with 1,227 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ode.bpel.eapi;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* Abstract class that bundles and registers <code>&lt;extensionActivity&gt;</code> and
* <code>&lt;extensionAssignOperation&gt;</code> implementations related to a particular namespace.
*
* @author Tammo van Lessen (University of Stuttgart)
*/
public abstract class AbstractExtensionBundle {
private Map<String, Class<? extends ExtensionOperation>> extensionsByName = new HashMap<String, Class<? extends ExtensionOperation>>();

/**
* Returns the extension namespace this bundle provides implementations for.
* @return
*/
public abstract String getNamespaceURI();

/**
* Register extension operations.
*/
public abstract void registerExtensionActivities();

/**
* Register an {@link ExtensionOperation} implementation as <code>&lt;extensionActivity&gt;</code>.
*
* @param localName
* @param activity
*/
protected final void registerExtensionOperation(String localName, Class<? extends ExtensionOperation> operation) {
extensionsByName.put(localName, operation);
}

/**
* Returns a list of the local names of registered extension operations.
*/
public final Set<String> getExtensionOperationNames() {
return Collections.unmodifiableSet(extensionsByName.keySet());
}

public final Class<? extends ExtensionOperation> getExtensionOperationClass(String localName) {
return extensionsByName.get(localName);
}

public final ExtensionOperation getExtensionOperationInstance(String localName) throws InstantiationException, IllegalAccessException {
return getExtensionOperationClass(localName).newInstance();
}

}
128 changes: 128 additions & 0 deletions bpel-api/src/main/java/org/apache/ode/bpel/eapi/ExtensionContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ode.bpel.eapi;

import java.util.List;
import java.util.Map;

import org.apache.ode.bpel.common.FaultException;
import org.apache.ode.bpel.o.OLink;
import org.apache.ode.bpel.o.OProcess;
import org.apache.ode.bpel.o.OScope;
import org.w3c.dom.Node;


/**
* Context for executing extension activities or extension assign operations.
* Implementations of the {@link ExtensionOperation} class use this interface to access BPEL
* variables, property sets and link status.
*
* @author Tammo van Lessen (University of Stuttgart)
*/
public interface ExtensionContext {

/**
* Returns a list of variables visible in the current scope.
*
* @return an unmodifiable list of visible variables.
* @throws FaultException
*/
Map<String, OScope.Variable> getVisibleVariables() throws FaultException;

/**
* Returns a list of links.
*
* @return an unmodifiable list of visible variables.
* @throws FaultException
*/
List<OLink> getLinks() throws FaultException;

/**
* Read the value of a BPEL variable.
*
* @param variable
* variable to read
* @param part
* the part (or <code>null</code>)
* @return the value of the variable, wrapped in a <code>Node</code>
*/
Node readVariable(OScope.Variable variable) throws FaultException;

/**
* Read the value of a BPEL variable.
*
* @param variableName
* variable to read
* @param part
* the part (or <code>null</code>)
* @return the value of the variable, wrapped in a <code>Node</code>
*/
Node readVariable(String variableName) throws FaultException;

/**
* Write the value into a BPEL variable.
*
* @param variable
* variable to write
* @param value
* the value to be stored into the variable
* @return the value of the variable, wrapped in a <code>Node</code>
*/
void writeVariable(OScope.Variable variable, Node value) throws FaultException;

/**
* Write the value into a BPEL variable.
*
* @param variableName
* variable to write
* @param value
* the value to be stored into the variable
* @return the value of the variable, wrapped in a <code>Node</code>
*/
void writeVariable(String variableName, Node value) throws FaultException;

/**
* Read the value of a BPEL property.
*
* @param variable
* variable containing property
* @param property
* property to read
* @return value of the property
*/
String readMessageProperty(OScope.Variable variable, OProcess.OProperty property)
throws FaultException;

/**
* Obtain the status of a control link.
*
* @param olink
* link to check
* @return <code>true</code> if the link is active, <code>false</code>
* otherwise.
*/
boolean isLinkActive(OLink olink) throws FaultException;

/**
* Reads the current process instance id.
* @return instance id
*/
Long getProcessId();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ode.bpel.eapi;

import org.apache.ode.bpel.common.FaultException;
import org.apache.ode.utils.SerializableElement;

/**
* This is the basis interface for implementations of
* <code>&lt;extensionAssignOperation&gt;</code> and <code>&lt;extensionActivity&gt;</code>
* nodes.
*
* Implementations of this interface must provide a default constructor as they are created
* using reflection.
*
* @see AbstractExtensionBundle
*
* @author Tammo van Lessen (University of Stuttgart)
*/
public interface ExtensionOperation {

void run(ExtensionContext context, SerializableElement element) throws FaultException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class BpelProcess {
DebuggerSupport _debugger;

ExpressionLanguageRuntimeRegistry _expLangRuntimeRegistry;

Set<String> _mustUnderstandExtensions;

private ReplacementMap _replacementMap;

Expand Down Expand Up @@ -1157,6 +1159,7 @@ private void doDehydrate() {
_endpointToMyRoleMap = null;
_replacementMap = null;
_expLangRuntimeRegistry = null;
_mustUnderstandExtensions = null;
}

private void doHydrate() {
Expand Down Expand Up @@ -1185,6 +1188,23 @@ private void doHydrate() {
}
_expLangRuntimeRegistry = elangRegistry;

// Checking for registered extension bundles, throw an exception when
// a "mustUnderstand" extension is not available
_mustUnderstandExtensions = new HashSet<String>();
for (OProcess.OExtension extension : _oprocess.declaredExtensions) {
if (extension.mustUnderstand) {
if (_contexts.extensionRegistry.get(extension.namespaceURI) == null) {
String msg = __msgs.msgExtensionMustUnderstandError(_pid, extension.namespaceURI);
__log.error(msg);
throw new BpelEngineException(msg);
} else {
_mustUnderstandExtensions.add(extension.namespaceURI);
}
} else {
__log.warn("The process declares the extension namespace " + extension.namespaceURI + " that is unkown to the engine");
}
}

setRoles(_oprocess);

if (!_hydratedOnce) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import org.apache.ode.bpel.dao.ProcessInstanceDAO;
import org.apache.ode.bpel.dao.ScopeDAO;
import org.apache.ode.bpel.dao.XmlDataDAO;
import org.apache.ode.bpel.eapi.AbstractExtensionBundle;
import org.apache.ode.bpel.eapi.ExtensionContext;
import org.apache.ode.bpel.eapi.ExtensionOperation;
import org.apache.ode.bpel.evt.*;
import org.apache.ode.bpel.iapi.BpelEngineException;
import org.apache.ode.bpel.iapi.ContextException;
Expand All @@ -68,6 +71,7 @@
import org.apache.ode.bpel.runtime.Selector;
import org.apache.ode.bpel.runtime.VariableInstance;
import org.apache.ode.bpel.runtime.channels.ActivityRecoveryChannel;
import org.apache.ode.bpel.runtime.channels.ExtensionResponseChannel;
import org.apache.ode.bpel.runtime.channels.FaultData;
import org.apache.ode.bpel.runtime.channels.InvokeResponseChannel;
import org.apache.ode.bpel.runtime.channels.PickResponseChannel;
Expand All @@ -79,6 +83,7 @@
import org.apache.ode.utils.GUID;
import org.apache.ode.utils.Namespaces;
import org.apache.ode.utils.ObjectPrinter;
import org.apache.ode.utils.SerializableElement;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -1184,4 +1189,67 @@ public void initializePartnersSessionId(PartnerLinkInstance pLink, String sessio
public void forceFlush() {
_forceFlush = true;
}

public void executeExtension(QName extensionId, ExtensionContext context, SerializableElement element, ExtensionResponseChannel extResponseChannel) throws FaultException {
__log.debug("Execute extension activity");
final String channelId = extResponseChannel.export();
ExtensionOperation ea = createExtensionActivityImplementation(extensionId);
if (ea == null) {
if (_bpelProcess._mustUnderstandExtensions.contains(extensionId.getNamespaceURI())) {
//TODO
__log.warn("Lookup of extension activity " + extensionId + " failed.");
throw new FaultException(new QName("urn:bpel20", "extlookup-failed"), "Lookup of extension activity " + extensionId + " failed.");
} else {
// act like <empty> - do nothing
completeExtensionExecution(channelId, null);
return;
}
}

try {
// should be running in a pooled thread
ea.run(context, element);
completeExtensionExecution(channelId, null);
} catch (RuntimeException e) {
__log.error("Error during execution of extension activity.", e);
completeExtensionExecution(channelId, e);
}
}

private void completeExtensionExecution(final String channelId, final Throwable t) {
if (t != null) {
_vpu.inject(new BpelJacobRunnable() {
private static final long serialVersionUID = -1L;

public void run() {
importChannel(channelId, ExtensionResponseChannel.class).onFailure(t);
}
});
} else {
_vpu.inject(new BpelJacobRunnable() {
private static final long serialVersionUID = -1L;

public void run() {
importChannel(channelId, ExtensionResponseChannel.class).onCompleted();
}
});
}
}

private ExtensionOperation createExtensionActivityImplementation(QName name) {
if (name == null) {
return null;
}
AbstractExtensionBundle bundle = _contexts.extensionRegistry.get(name.getNamespaceURI());
if (bundle == null) {
return null;
} else {
try {
return (ExtensionOperation)bundle.getExtensionOperationInstance(name.getLocalPart());
} catch (Exception e) {
return null;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.ode.bpel.dao.BpelDAOConnectionFactory;
import org.apache.ode.bpel.dao.MessageExchangeDAO;
import org.apache.ode.bpel.dao.ProcessDAO;
import org.apache.ode.bpel.eapi.AbstractExtensionBundle;
import org.apache.ode.bpel.evt.BpelEvent;
import org.apache.ode.bpel.iapi.BindingContext;
import org.apache.ode.bpel.iapi.BpelEngineException;
Expand Down Expand Up @@ -245,6 +246,15 @@ private void unregisterBpelEventListeners() {
}
}

public void registerExtensionBundle(AbstractExtensionBundle bundle) {
_contexts.extensionRegistry.put(bundle.getNamespaceURI(), bundle);
bundle.registerExtensionActivities();
}

public void unregisterExtensionBundle(String nsURI) {
_contexts.extensionRegistry.remove(nsURI);
}

public void stop() {
_mngmtLock.writeLock().lock();
try {
Expand Down

0 comments on commit 1e8798c

Please sign in to comment.