Beispiel #1
0
 private BackEndManager initBEManager() {
   try {
     return BackEndManager.getInstance(null);
   } catch (Exception e) {
     myLogger.log(Logger.WARNING, "Cannot retrieve BackEndManager. " + e);
     e.printStackTrace();
   }
   return null;
 }
Beispiel #2
0
 public Object serviceInvokation(
     String actor, String serviceName, String methodName, Object[] methodParams)
     throws NotFoundException, ServiceException, IMTPException {
   AID id = new AID(actor, AID.ISLOCALNAME);
   AgentImage image = getAgentImage(id);
   ServiceHelper helper = image.getHelper(serviceName);
   if (helper == null) {
     throw new ServiceException("Service " + serviceName + "does not have a Service-helper");
   }
   BECodec codec = getBECodec(serviceName);
   Object[] decodedParams = codec.decodeParams(methodName, methodParams);
   try {
     Method m = null;
     Method[] mm = helper.getClass().getMethods();
     for (int i = 0; i < mm.length; ++i) {
       if (mm[i].getName().equals(methodName)) {
         if (isCompatible(mm[i], decodedParams)) {
           m = mm[i];
           break;
         }
       }
     }
     if (m != null) {
       if (!m.isAccessible()) {
         try {
           m.setAccessible(true);
         } catch (SecurityException se) {
           throw new NoSuchMethodException(
               "Method "
                   + methodName
                   + "() of class "
                   + getClass().getName()
                   + " not accessible.");
         }
       }
       Object result = m.invoke(helper, decodedParams);
       return codec.encodeResult(methodName, result);
     } else {
       throw new ServiceException("No valid " + methodName + " method found in service helper");
     }
   } catch (ServiceException se) {
     throw se;
   } catch (Exception e) {
     e.printStackTrace();
     throw new ServiceException("Unexpected error, ", e);
   }
 }
Beispiel #3
0
  public boolean connect() {
    try {
      // Initialize the BackEndManager if required
      if (myProfile.getBooleanProperty(USE_BACKEND_MANAGER, false)) {
        theBEManager = initBEManager();
      }

      Vector agentSpecs =
          Specifier.parseSpecifierList(myProfile.getParameter(Profile.AGENTS, null));
      myProfile.setParameter(Profile.AGENTS, null);

      myFrontEnd = myConnectionManager.getFrontEnd(this, null);
      myLogger.log(
          Logger.FINE,
          "BackEnd container "
              + myProfile.getParameter(Profile.CONTAINER_NAME, null)
              + " joining the platform ... (FrontEnd version: "
              + myProfile.getParameter(JICPProtocol.VERSION_KEY, "not available")
              + ")");

      Runtime.instance().beginContainer();
      boolean connected = joinPlatform();
      if (connected) {
        myLogger.log(Logger.FINE, "Join platform OK");
        AID amsAID = getAMS();
        myProfile.setParameter(Profile.PLATFORM_ID, amsAID.getHap());
        String[] addresses = amsAID.getAddressesArray();
        if (addresses != null) {
          StringBuffer sb = new StringBuffer();
          for (int i = 0; i < addresses.length; i++) {
            sb.append(addresses[i]);
            if (i < addresses.length - 1) {
              sb.append(';');
            }
          }
          myProfile.setParameter(MicroRuntime.PLATFORM_ADDRESSES_KEY, sb.toString());
        }
        if ("true".equals(myProfile.getParameter(RESYNCH, "false"))) {
          myLogger.log(
              Logger.INFO,
              "BackEnd container "
                  + myProfile.getParameter(Profile.CONTAINER_NAME, null)
                  + " activating re-synch ...");
          resynch();
        } else {
          // Notify the main container about bootstrap agents on the FE.
          for (int i = 0; i < agentSpecs.size(); i++) {
            Specifier sp = (Specifier) agentSpecs.elementAt(i);
            try {
              String name = bornAgent(sp.getName());
              sp.setClassName(name);
              sp.setArgs(null);
            } catch (Exception e) {
              myLogger.log(Logger.SEVERE, "Error creating agent " + sp.getName(), e);
              sp.setClassName(e.getClass().getName());
              sp.setArgs(new Object[] {e.getMessage()});
            }
          }
          myProfile.setParameter(Profile.AGENTS, Specifier.encodeSpecifierList(agentSpecs));
        }
      }
      return connected;
    } catch (Exception e) {
      // Should never happen
      e.printStackTrace();
      return false;
    }
  }