Search in sources :

Example 1 with RemoteException

use of si.ijs.acs.objectexplorer.engine.RemoteException 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 */
}
Also used : Invocation(si.ijs.acs.objectexplorer.engine.Invocation) Any(org.omg.CORBA.Any) Request(org.omg.CORBA.Request) OperationDescription(org.omg.CORBA.OperationDescription) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) AcsJException(alma.acs.exceptions.AcsJException) DataException(si.ijs.acs.objectexplorer.engine.DataException) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException)

Example 2 with RemoteException

use of si.ijs.acs.objectexplorer.engine.RemoteException in project ACS by ACS-Community.

the class BACIRemoteAccess method internalParentConnect.

/**
	 * Insert the method's description here.
	 * Creation date: (2.11.2000 0:35:23)
	 * @param baciNode si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteNode
	 */
private void internalParentConnect(BACIRemoteNode baciNode, boolean doSync) {
    /* we are using the parent to query the object as either an IDL attribute or
			   Java property accessor design pattern (returns Object type, takes no parameters)
		*/
    //	System.out.println("IPC");
    String targetName = null;
    TypeCode retType = null;
    String id = null;
    if (baciNode.getNodeType() == ATTRIBUTE) {
        AttributeDescription ad = (AttributeDescription) baciNode.getUserObject();
        try {
            id = ad.type.id();
        } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
            throw new RemoteException("IDL: BadKind thrown on type id lookup for PROPERTY child of the remote node: " + bk);
        }
        targetName = BACIIntrospector.attributeNameToMethodName(ad.name);
        retType = ad.type;
        notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Obtaining IDL attribute reference for '" + ad.name + "'.");
    } else if (baciNode.getNodeType() == PROPERTY) {
        OperationDescription od = (OperationDescription) baciNode.getUserObject();
        try {
            id = od.result.id();
        } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
            throw new RemoteException("IDL: BadKind thrown on type id lookup for PROPERTY child of the remote node: " + bk);
        }
        targetName = od.name;
        retType = od.result;
        notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Obtaining reference to contained object through property accessor design pattern for '" + od.name + ".");
    } else
        throw new IntrospectionInconsistentException("Devices can contain objects only as IDL attributes or property accessor design patterns. Failed on '" + baciNode + "'.");
    BACIRemoteNode parentNode = (BACIRemoteNode) baciNode.getParent();
    if (parentNode.getCORBARef() == null) {
        parentNode.connect();
        if (parentNode.getCORBARef() == null)
            throw new RemoteException("Child node is accessible although the parent node CORBA reference is null. Failed on '" + baciNode + ".");
    }
    /* begin DII stanza */
    Request req = parentNode.getCORBARef()._request(targetName);
    req.set_return_type(retType);
    notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Invoking remote call...");
    req.invoke();
    Any returnValue = req.return_value();
    if (returnValue.type().kind() != TCKind.tk_objref)
        throw new IntrospectionInconsistentException("Return type of '" + targetName + "' is not of type object reference, expected object reference because of BACI containment specifications.");
    baciNode.setCORBARef(returnValue.extract_Object());
    //
    baciNode.setIFDesc(getIFDesc(id));
    //
    if (baciNode.getCORBARef() != null)
        notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Connection to contained object OK.");
    else
        notifier.reportError("Reference returned when resolving contained object '" + targetName + "' is null.");
/* end DII stanza */
}
Also used : TypeCode(org.omg.CORBA.TypeCode) Request(org.omg.CORBA.Request) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) Any(org.omg.CORBA.Any) OperationDescription(org.omg.CORBA.OperationDescription) AttributeDescription(org.omg.CORBA.AttributeDescription) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException)

Example 3 with RemoteException

use of si.ijs.acs.objectexplorer.engine.RemoteException in project ACS by ACS-Community.

the class BACIRemoteAccess method resolveManager.

/**
	 * Insert the method's description here.
	 * Creation date: (1.11.2000 14:29:17)
	 */
private void resolveManager() {
    if (managerLoc == null)
        throw new IllegalStateException("Cannot resolve manager corbaloc when it is null.");
    try {
        org.omg.CORBA.Object object = orb.string_to_object(managerLoc);
        notifier.reportDebug("BACIRemoteAccess::resolveManager", "Manager reference string_to_object OK with managerLoc = '" + managerLoc + "'.");
        manager = ManagerHelper.narrow(object);
        notifier.reportDebug("BACIRemoteAccess::resolveManager", "Manager reference narrowing OK.");
        notifier.reportMessage("Obtained reference to 'Manager'.");
        if (manager == null)
            throw new NullPointerException("Manager is null after ManagerHelper.narrow()");
    } catch (Exception e) {
        throw new RemoteException("Could not resolve manager reference: " + e);
    }
    try {
        client = new ClientImpl();
        Client cIF = client._this(orb);
        notifier.reportDebug("BACIRemoteAccess::resolveManager", "Instantiated Client servant.");
        ClientInfo info = manager.login(cIF);
        if (info == null)
            throw new Exception("Failed to login to the manager when returned ClientInfo is null.");
        handle = info.h;
        notifier.reportDebug("BACIRemoteAccess::resolveManager", "Manager login OK.");
    } catch (Exception e1) {
        throw new RemoteException("Cannot login to the manager: " + e1);
    }
    new Thread(new Runnable() {

        public void run() {
            notifier.reportDebug("BACIRemoteAccess::resolveManager", "Initializing remote logging...");
            ClientLogManager.getAcsLogManager().initRemoteLogging(orb, manager, handle, true);
            notifier.reportDebug("BACIRemoteAccess::resolveManager", "Remote logging initialized.");
        }
    }, "InitRemoteLogging").start();
}
Also used : ClientInfo(si.ijs.maci.ClientInfo) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) Client(si.ijs.maci.Client) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) AcsJException(alma.acs.exceptions.AcsJException) DataException(si.ijs.acs.objectexplorer.engine.DataException) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException)

Example 4 with RemoteException

use of si.ijs.acs.objectexplorer.engine.RemoteException in project ACS by ACS-Community.

the class BACIIntrospector method isOfType.

/**
 * Insert the method's description here.
 * Creation date: (13.11.2000 18:44:35)
 * @return boolean
 * @param tc org.omg.CORBA.TypeCode
 * @param baciType java.lang.String
 */
private boolean isOfType(TypeCode tc, String type) {
    switch(tc.kind().value()) {
        case TCKind._tk_objref:
            break;
        case TCKind._tk_alias:
            try {
                return isOfType(tc.content_type(), type);
            } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
                throw new RemoteException("Exception while analyzing typecode (getting typecode name raises exception). Exception: " + bk);
            }
        default:
            return false;
    }
    try {
        ra.getNotifier().reportDebug("BACIIntrospector::isOfType", "Checking if '" + tc.id() + "' implements '" + type + "'.");
        if (tc.id().equals(ID_CORBA_OBJECT))
            if (type.equals(ID_CORBA_OBJECT))
                return true;
            else
                return false;
        /*	Class c = Class.forName(IDtoClassName(tc.id()));
		Class c1 = null;
		try
		{ 
			c1 = Class.forName(addJavaPackagePrefix(baciType));
		} catch (Exception e)
		{
			throw new JavaIDLIntrospectionException("Introspection error while loading property class '" + addJavaPackagePrefix(baciType) + "'.");
		}
		if (c1.isAssignableFrom(c)) return true;*/
        InterfaceDef idef = InterfaceDefHelper.narrow(ra.lookupId(tc.id()));
        if (idef.is_a(type))
            return true;
    } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
        throw new RemoteException("Exception while analyzing typecode (getting typecode name raises exception). Exception: " + bk);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return false;
}
Also used : InterfaceDef(org.omg.CORBA.InterfaceDef) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) DataException(si.ijs.acs.objectexplorer.engine.DataException)

Example 5 with RemoteException

use of si.ijs.acs.objectexplorer.engine.RemoteException in project ACS by ACS-Community.

the class BACIRemoteAccess method invokeAccessor.

/**
	 * Insert the method's description here.
	 * Creation date: (7.11.2000 22:52:30)
	 * @return si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteCall
	 * @param att si.ijs.acs.objectexplorer.engine.BACI.BACIAttribute
	 */
BACIRemoteCall invokeAccessor(BACIAttribute att) {
    if (att == null)
        throw new NullPointerException("att");
    BACIRemote target = (BACIRemote) att.getIntrospectable();
    if (target.getCORBARef() == null)
        throw new RemoteException("Cannot invoke attribute accessor '" + att + "' on object '" + target.getName() + "' because it is not connected.");
    org.omg.CORBA.Object remote = target.getCORBARef();
    AttributeDescription desc = att.getAttributeDesc();
    /* begin DII stanza */
    Request req = remote._request(BACIIntrospector.attributeNameToMethodName(desc.name));
    req.set_return_type(desc.type);
    java.lang.Object[] params = new java.lang.Object[0];
    int time = 0;
    notifier.reportMessage("Invoking accessor '" + target.getName() + "." + att + "()'.");
    notifier.reportDebug("BACIRemoteAccess::invokeAccessor", "Sending deferred attribute accessor '" + target.getName() + "." + att + "()'.");
    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 '" + att + "' on '" + target.getName() + "'.");
                return new BACIRemoteCall(target, att, params, null, true, null);
            }
        }
        // check exception
        checkException(target, req);
        notifier.reportDebug("BACIRemoteAccess::invokeAccessor", "Received response for '" + target.getName() + "." + att + "()'.");
        //	req.get_response();
        Any anyRet = req.return_value();
        java.lang.Object oRet = null;
        if (anyRet != null)
            oRet = baciIntrospector.extractAny(anyRet);
        notifier.reportDebug("BACIRemoteAccess::invokeAccessor", "Successfully unpacked response for '" + target.getName() + "." + att + "()'.");
        return new BACIRemoteCall(target, att, params, oRet, false, null);
    } catch (Exception e) {
        notifier.reportError("Exception during deferred remote invocation.", e);
        return new BACIRemoteCall(target, att, params, null, false, e);
    }
/* end DII stanza */
}
Also used : Request(org.omg.CORBA.Request) Any(org.omg.CORBA.Any) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) AcsJException(alma.acs.exceptions.AcsJException) DataException(si.ijs.acs.objectexplorer.engine.DataException) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) AttributeDescription(org.omg.CORBA.AttributeDescription) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException)

Aggregations

IntrospectionInconsistentException (si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException)7 RemoteException (si.ijs.acs.objectexplorer.engine.RemoteException)7 DataException (si.ijs.acs.objectexplorer.engine.DataException)5 NonStickyConnectFailedRemoteException (si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException)5 AcsJException (alma.acs.exceptions.AcsJException)3 Any (org.omg.CORBA.Any)3 OperationDescription (org.omg.CORBA.OperationDescription)3 Request (org.omg.CORBA.Request)3 AttributeDescription (org.omg.CORBA.AttributeDescription)2 ArrayList (java.util.ArrayList)1 InterfaceDef (org.omg.CORBA.InterfaceDef)1 ParameterDescription (org.omg.CORBA.ParameterDescription)1 TypeCode (org.omg.CORBA.TypeCode)1 DataStruct (si.ijs.acs.objectexplorer.engine.DataStruct)1 DataType (si.ijs.acs.objectexplorer.engine.DataType)1 Invocation (si.ijs.acs.objectexplorer.engine.Invocation)1 Client (si.ijs.maci.Client)1 ClientInfo (si.ijs.maci.ClientInfo)1