operationcontext.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,097 行 · 第 1/3 页
JAVA
1,097 行
out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
} else {
out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
metaAxisOperation = new MetaDataEntry(axisOperation.getClass().getName(),
axisOperation.getName().toString());
ObjectStateUtils.writeObject(out, metaAxisOperation,
logCorrelationIDString + ".metaAxisOperation");
}
// save the meta data for the corresponding axis service to better
// match up the axis operation
String axisServMarker = logCorrelationIDString + ".metaAxisService";
ObjectStateUtils.writeString(out, axisServMarker, axisServMarker);
AxisService axisService = axisOperation.getAxisService();
if (axisService == null) {
out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
} else {
out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
metaAxisService =
new MetaDataEntry(axisService.getClass().getName(), axisService.getName());
ObjectStateUtils
.writeObject(out, metaAxisService, logCorrelationIDString + ".metaAxisService");
}
//---------------------------------------------------------
// parent
//---------------------------------------------------------
ServiceContext myParent = this.getServiceContext();
ObjectStateUtils
.writeObject(out, myParent, logCorrelationIDString + ".parent ServiceContext");
//---------------------------------------------------------
// HashMap messageContexts table
//---------------------------------------------------------
// NOTES: The assumption is that the table contains message contexts
// that are in the OperationContext hierarchy. To reduce overlap
// of object information that is being saved, extract the
// message context objects from the hierachy before saving.
// When the OperationContext is restored, the "slimmed down"
// message context objects are plugged back into the hierachy
// using the restored OperationContext as a basis.
// first deal with the original messageContexts table
HashMap tmpMsgCtxMap = null;
if ((messageContexts != null) && (!messageContexts.isEmpty())) {
// create a table of the non-isolated message contexts
workingSet = new HashMap();
tmpMsgCtxMap = new HashMap();
Set keySet = messageContexts.keySet();
Iterator itKeys = keySet.iterator();
while (itKeys.hasNext()) {
// expect the key to be a string
String keyObj = (String) itKeys.next();
// get the message context associated with that label
MessageContext value = (MessageContext) messageContexts.get(keyObj);
boolean addToWorkingSet = true;
// check to see if this message context was isolated
if (isolatedMessageContexts != null) {
if (!isolatedMessageContexts.isEmpty()) {
// see if the message context was previously isolated
MessageContext valueIsolated =
(MessageContext) isolatedMessageContexts.get(keyObj);
if (valueIsolated != null) {
String idIsol = valueIsolated.getMessageID();
if (idIsol != null) {
if (idIsol.equals(value.getMessageID())) {
// don't add to working set
addToWorkingSet = false;
}
}
}
}
}
if (addToWorkingSet) {
// put the meta data entry in the list
workingSet.put(keyObj, value);
}
}
// now we have a working set
Set keySet2 = workingSet.keySet();
Iterator itKeys2 = keySet2.iterator();
while (itKeys2.hasNext()) {
// expect the key to be a string
String keyObj2 = (String) itKeys2.next();
// get the message context associated with that label
MessageContext value2 = (MessageContext) workingSet.get(keyObj2);
// construct a copy of the message context
// that has been extracted from the object hierarchy
MessageContext modifiedValue2 = value2.extractCopyMessageContext();
// put the modified entry in the list
tmpMsgCtxMap.put(keyObj2, modifiedValue2);
// trace point
log.trace(logCorrelationIDString +
":writeExternal(): getting working set entry key [" + keyObj2 +
"] message context ID[" + modifiedValue2.getMessageID() + "]");
}
}
ObjectStateUtils.writeHashMap(out, tmpMsgCtxMap,
logCorrelationIDString + ".messageContexts working set");
// next, deal with the metadata table of messageContexts
ObjectStateUtils.writeHashMap(out, metaMessageContextMap, logCorrelationIDString +
".metaMessageContextMap metadata table");
//---------------------------------------------------------
// done
//---------------------------------------------------------
}
/**
* Restore the contents of the object that was previously saved.
* <p/>
* NOTE: The field data must read back in the same order and type
* as it was written. Some data will need to be validated when
* resurrected.
*
* @param in The stream to read the object contents from
* @throws IOException
* @throws ClassNotFoundException
*/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// set the flag to indicate that the message context is being
// reconstituted and will need to have certain object references
// to be reconciled with the current engine setup
needsToBeReconciled = true;
// trace point
log.trace(myClassName + ":readExternal(): BEGIN bytes available in stream [" +
in.available() + "] ");
//---------------------------------------------------------
// object level identifiers
//---------------------------------------------------------
// serialization version ID
long suid = in.readLong();
// revision ID
int revID = in.readInt();
// make sure the object data is in a version we can handle
if (suid != serialVersionUID) {
throw new ClassNotFoundException(ObjectStateUtils.UNSUPPORTED_SUID);
}
// make sure the object data is in a revision level we can handle
if (revID != REVISION_1) {
throw new ClassNotFoundException(ObjectStateUtils.UNSUPPORTED_REVID);
}
//---------------------------------------------------------
// various simple fields
//---------------------------------------------------------
long time = in.readLong();
setLastTouchedTime(time);
isComplete = in.readBoolean();
key = ObjectStateUtils.readString(in, "OperationContext.key");
logCorrelationIDString =
ObjectStateUtils.readString(in, "OperationContext.logCorrelationIDString");
// trace point
log.trace(myClassName + ":readExternal(): reading input stream for [" +
logCorrelationIDString + "] ");
//---------------------------------------------------------
// properties
//---------------------------------------------------------
HashMap tmpHashMap = ObjectStateUtils.readHashMap(in, "OperationContext.properties");
properties = new HashMap();
if (tmpHashMap != null) {
setProperties(tmpHashMap);
}
//---------------------------------------------------------
// axis operation meta data
//---------------------------------------------------------
// axisOperation is not usable until the meta data has been reconciled
axisOperation = null;
ObjectStateUtils.readString(in, "OperationContext.axisOperation");
boolean metaAxisOperationIsActive = in.readBoolean();
if (metaAxisOperationIsActive == ObjectStateUtils.ACTIVE_OBJECT) {
metaAxisOperation = (MetaDataEntry) ObjectStateUtils
.readObject(in, "OperationContext.metaAxisOperation");
} else {
metaAxisOperation = null;
}
// axisService is not usable until the meta data has been reconciled
ObjectStateUtils.readString(in, "OperationContext.axisService");
boolean metaAxisServiceIsActive = in.readBoolean();
if (metaAxisServiceIsActive == ObjectStateUtils.ACTIVE_OBJECT) {
metaAxisService = (MetaDataEntry) ObjectStateUtils
.readObject(in, "OperationContext.metaAxisService");
} else {
metaAxisService = null;
}
//---------------------------------------------------------
// parent
//---------------------------------------------------------
// ServiceContext is not usable until it has been activated
metaParent = (ServiceContext) ObjectStateUtils
.readObject(in, "OperationContext.parent ServiceContext");
//---------------------------------------------------------
// HashMap messageContexts table
//---------------------------------------------------------
// set to empty until this can be activiated
messageContexts = new HashMap();
workingSet = ObjectStateUtils
.readHashMap(in, logCorrelationIDString + ".messageContexts working set");
metaMessageContextMap = ObjectStateUtils
.readHashMap(in, logCorrelationIDString + ".metaMessageContextMap metadata table");
//---------------------------------------------------------
// done
//---------------------------------------------------------
}
/**
* This method checks to see if additional work needs to be
* done in order to complete the object reconstitution.
* Some parts of the object restored from the readExternal()
* cannot be completed until we have a configurationContext
* from the active engine. The configurationContext is used
* to help this object to plug back into the engine's
* configuration and deployment objects.
*
* @param cc The configuration context object representing the active configuration
*/
public void activate(ConfigurationContext cc) {
// see if there's any work to do
if (!needsToBeReconciled) {
// return quick
return;
}
// get the axis configuration
AxisConfiguration axisConfig = cc.getAxisConfiguration();
// We previously saved metaAxisService; restore it
AxisService axisService = null;
if (metaAxisService != null) {
axisService = ObjectStateUtils.findService(axisConfig, metaAxisService.getClassName(),
metaAxisService.getQNameAsString());
}
// We previously saved metaAxisOperation; restore it
if (metaAxisOperation != null) {
if (axisService != null) {
this.axisOperation = ObjectStateUtils.findOperation(axisService,
metaAxisOperation.getClassName(),
metaAxisOperation.getQName());
} else {
this.axisOperation = ObjectStateUtils.findOperation(axisConfig,
metaAxisOperation.getClassName(),
metaAxisOperation.getQName());
}
}
// the parent ServiceContext object was saved
// either use the restored object or sync up with
// an existing ServiceContext object
if (metaParent != null) {
// find out if a copy of the ServiceContext object exists on this
// engine where this OperationContext is being restored/activated
// if so, use that object instead of the restored object
// in order to make sure that future changes to service-level
// properties are preserved for future operations
String groupName = metaParent.getGroupName();
String serviceName = metaParent.getName();
ServiceContext existingSC = null;
// first look for the ServiceContext via the ServiceContextGroup
ServiceGroupContext sgc = cc.getServiceGroupContext(groupName);
if (sgc != null) {
existingSC = sgc.findServiceContext(serviceName);
}
if (existingSC == null) {
// we couldn't find the ServiceContext via the ServiceContextGroup
// try via the set of existing operation contexts
OperationContext existingOC =
cc.findOperationContext(getOperationName(), serviceName, groupName);
if (existingOC != null) {
existingSC = (ServiceContext) existingOC.getParent();
}
}
if (existingSC == null) {
// could not find an existing ServiceContext
// use the restored object
metaParent.activate(cc);
// set parent
this.setParent(metaParent);
} else {
// switch over to the existing object
this.setParent(existingSC);
// do a copy of the properties from the restored object
// to the existing ServiceContext
// Should the copy be a non-destructive one? That is,
// if the key already exists in the properties table of the
// existing object, should the value be overwritten from the
// restored ojbect? For now, the decision is that the state
// that has been preserved for a saved context object is
// is important to be restored.
metaParent.putContextProperties(existingSC, true);
}
} else {
// set parent to null
this.setParent(metaParent);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?