use of si.ijs.acs.objectexplorer.engine.Invocation in project ACS by ACS-Community.
the class BACIRemoteAccess method internalInvokeTrivial.
/**
* Insert the method's description here.
* Creation date: (2.11.2000 18:08:01)
* @return si.ijs.acs.objectexplorer.engine.Invocation
* @param target si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteNode
* @param op si.ijs.acs.objectexplorer.engine.Operation
*/
private BACIRemoteCall internalInvokeTrivial(BACIRemote target, Operation op, java.lang.Object[] params) {
if (target.getCORBARef() == null)
throw new RemoteException("Cannot invoke operation '" + op.getName() + "' on object '" + target.getName() + "' because it is not connected.");
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Preparing DII parameters for '" + target.getName() + "." + op.getName() + "()'.");
java.lang.Object[] allArguments = baciIntrospector.prepareDIIparameters(((BACIOperation) op).getOperationDesc(), params);
org.omg.CORBA.Object remote = target.getCORBARef();
OperationDescription desc = ((BACIOperation) op).getOperationDesc();
if (allArguments.length != desc.parameters.length)
throw new IllegalStateException("BACI introspector returned an array of values the length of which does not match CORBA parameter list, object = '" + target.getName() + "', operation = '" + op.getName() + "'.");
StringBuffer buf = new StringBuffer(200);
for (int i = 0; i < params.length; i++) {
buf.append("'");
buf.append(op.getParameterNames()[i]);
buf.append("' = '");
buf.append(params[i]);
buf.append("' ");
}
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Parameters for '" + op.getName() + "': " + buf.toString());
notifier.reportMessage("Invoking '" + target.getName() + "." + op.getName() + "()', parameters: " + buf.toString());
/* begin DII stanza */
Request req = remote._request(op.getName());
req.set_return_type(desc.result);
/* set exceptions */
org.omg.CORBA.ExceptionList exceptions = req.exceptions();
org.omg.CORBA.ExceptionDescription[] exceptionsDesc = desc.exceptions;
for (int i = 0; i < exceptionsDesc.length; i++) {
// TAO IFR bug workaround
if (exceptionsDesc[i].type.kind().value() != TCKind._tk_except) {
// System.out.println("--> Invalid user exception kind, fixing...");
Class c = null;
String className = null;
try {
className = baciIntrospector.IDtoClassName(exceptionsDesc[i].type.id()) + "Helper";
c = Class.forName(className);
} catch (Exception e) {
throw new JavaIDLIntrospectionException("Failed to load class '" + className + "'. Introspection failed on typedef argument: " + e);
}
Class[] paramTypes = {};
java.lang.Object[] paramVals = {};
try {
java.lang.Object retVal = c.getMethod("type", paramTypes).invoke(null, paramVals);
exceptions.add((TypeCode) retVal);
} catch (Exception e1) {
throw new JavaIDLIntrospectionException("Dynamic invocation of 'internalInvokeTrivial' failed on a typedef argument. Class instance: " + c.getName() + ". Exception:" + e1);
}
} else
exceptions.add(exceptionsDesc[i].type);
}
for (int i = 0; i < allArguments.length; i++) {
Any argument = orb.create_any();
argument.type(desc.parameters[i].type);
if (desc.parameters[i].mode != ParameterMode.PARAM_OUT) {
argument = baciIntrospector.insertAny(desc.parameters[i].type, argument, allArguments[i]);
//baciIntrospector.displayAny(argument);
}
//org.omg.CORBA.ParameterMode.PARAM_xxx is defined in [0-2] and in org.jacorb.orb.ARG_xxx is defined in [1-3].
req.arguments().add_value(desc.parameters[i].name, argument, desc.parameters[i].mode.value() + 1);
}
// invoke request
if (desc.mode == OperationMode.OP_ONEWAY) {
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Sending oneway request '" + target.getName() + "." + op.getName() + "()'...");
try {
req.send_oneway();
return new BACIRemoteCall(target, (BACIOperation) op, params, null, null);
} catch (Exception e) {
notifier.reportError("Exception during oneway remote invocation.", e);
return new BACIRemoteCall(target, (BACIOperation) op, params, e);
}
} else {
int time = 0;
boolean errorResponse = false;
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Sending deferred request '" + target.getName() + "." + op.getName() + "()'.");
try {
req.send_deferred();
while (!req.poll_response()) {
try {
Thread.sleep(POLL_SLEEP);
time += POLL_SLEEP;
} catch (InterruptedException ie) {
}
if (time > POLL_TIMEOUT) {
notifier.reportError("Timeout (" + POLL_TIMEOUT + " ms) while polling for response from '" + op.getName() + "' on '" + target.getName() + "'.");
return new BACIRemoteCall(target, (BACIOperation) op, params, true);
}
}
// check exception
checkException(target, req);
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Received response for '" + target.getName() + "." + op.getName() + "()'.");
// req.get_response();
Any anyRet = req.return_value();
java.lang.Object oRet = null;
if (anyRet != null)
oRet = baciIntrospector.extractAny(anyRet);
java.lang.Object[] outs = baciIntrospector.extractOuts(req, desc);
// check for error-type ACSCompletion-s
errorResponse = checkFromACSCompletion(oRet);
for (int i = 0; i < outs.length; i++) errorResponse |= checkFromACSCompletion(outs[i]);
if (target instanceof Invocation && baciIntrospector.isInvocationDestroyMethod(op.getName()))
new CBTimer((BACIInvocation) target).start();
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Successfully unpacked response for '" + target.getName() + "." + op.getName() + "()'.");
BACIRemoteCall remoteCall = new BACIRemoteCall(target, (BACIOperation) op, params, oRet, outs);
remoteCall.setErrorResponse(errorResponse);
return remoteCall;
} catch (Exception e) {
notifier.reportError("Exception during deferred remote invocation.", e);
return new BACIRemoteCall(target, (BACIOperation) op, params, e);
}
}
/* end DII stanza */
}
Aggregations