コード例 #1
0
  @Override
  public Future<List<Service>> searchServices(Service filter, IIdentity node)
      throws ServiceDiscoveryException {

    if (logger.isDebugEnabled())
      logger.debug("Searching repository for a given service, on node: " + node.getJid());
    List<Service> result = new ArrayList<Service>();

    try {

      String myLocalJid = getCommMngr().getIdManager().getThisNetworkNode().getJid();

      if (myLocalJid.equals(node.getJid())) {
        if (logger.isDebugEnabled()) logger.debug("It's the local node, so we do a local call");
        return searchServices(filter);
      }

      if (logger.isDebugEnabled()) logger.debug("Trying to query the remote node...");

      ServiceDiscoveryRemoteClient callback = new ServiceDiscoveryRemoteClient();
      getServiceDiscoveryRemote().searchService(filter, node, callback);
      result = callback.getResultList();

    } catch (Exception ex) {
      ex.printStackTrace();
      logger.error("Exception while searching for services!");
      throw new ServiceDiscoveryException("Exception while searching for services!", ex);
    }

    return new AsyncResult<List<Service>>(result);
  }
コード例 #2
0
  @Override
  public Future<Service> getService(ServiceResourceIdentifier serviceId)
      throws ServiceDiscoveryException {

    if (logger.isDebugEnabled()) logger.debug("Service Discovery::getService()");

    Service result = null;
    try {
      // First we check the local repository
      result = getServiceReg().retrieveService(serviceId);

      // Did we find it there?
      if (result == null) {
        if (logger.isDebugEnabled())
          logger.debug(
              "Didn't find service on local repository, now checking if it's a remote service!");

        String myLocalJid = getCommMngr().getIdManager().getThisNetworkNode().getJid();
        String serviceJid = ServiceModelUtils.getJidFromServiceIdentifier(serviceId);

        // Is it supposed to be local?
        if (!myLocalJid.equals(serviceJid)) {

          if (logger.isDebugEnabled())
            logger.debug("It's a remote service from node: " + serviceJid);

          INetworkNode node = getCommMngr().getIdManager().fromFullJid(serviceJid);

          // We call the other network node to get the information on the service
          ServiceDiscoveryRemoteClient callback = new ServiceDiscoveryRemoteClient();
          getServiceDiscoveryRemote().getService(serviceId, node, callback);
          List<Service> resultList = callback.getResultList();

          // Only one service should be returned. If not, we're dealing with some sort of problem
          if (resultList.size() == 1) {
            result = resultList.get(0);
            if (logger.isDebugEnabled()) logger.debug("Found service remotely!");
          }
        }
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      logger.error("getService():: Exception getting Service: " + ex);
      throw new ServiceDiscoveryException("getService():: Exception getting Service", ex);
    }

    if (result == null) return null;
    else return new AsyncResult<Service>(result);
  }
コード例 #3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.societies.api.internal.servicelifecycle.IServiceDiscovery#getServices
   * (org.societies.api.comm.xmpp.datatypes.Identity)
   */
  @Override
  @Async
  public Future<List<Service>> getServices(IIdentity node) throws ServiceDiscoveryException {
    List<Service> serviceList = new ArrayList<Service>();

    if (logger.isDebugEnabled())
      logger.debug("getServices(Identity node) for node: " + node.getJid());

    boolean myNode;
    boolean myCIS = false;
    INetworkNode currentNode = commMngr.getIdManager().getThisNetworkNode();
    if (!currentNode.getJid().contentEquals(node.getJid())) myNode = false;
    else myNode = true;

    try {
      // Is it our node? If so, local search
      if (myNode) {
        if (logger.isDebugEnabled()) logger.debug("We're dealing with our own node!");
        serviceList = getServiceReg().retrieveServicesSharedByCSS(node.getJid());
      } else {
        // Is it one of my CIS? If so, local search
        ICisOwned localCis = getCisManager().getOwnedCis(node.getJid());
        if (localCis != null) {
          if (logger.isDebugEnabled()) logger.debug("We're dealing with our CIS! Local search!");
          serviceList = getServiceReg().retrieveServicesSharedByCIS(node.getJid());
          myCIS = true;
        }
      }
      /*
      switch (node.getType())
      {
      case CSS:
      case CSS_RICH:
      case CSS_LIGHT:
      	serviceList = getServiceReg().retrieveServicesSharedByCSS(node.getJid());
      	break;
      case CIS:
      	if(logger.isDebugEnabled()) logger.debug("Retrieving services of a CIS");
      	ICisOwned myCis = getCisManager().getOwnedCis(node.getJid());
      	if(myCis != null){
      		if(logger.isDebugEnabled()) logger.debug("We're dealing with our CIS! Local search!");
      		serviceList = getServiceReg().retrieveServicesSharedByCIS(node.getJid());
      	}
      	break;
      default:
      	logger.warn("Unknown node!");
      	break;
      }
      */
    } catch (ServiceRetrieveException e) {

      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception e) {

      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    if (serviceList == null || serviceList.isEmpty()) {
      if (logger.isDebugEnabled()) logger.debug("No services retrieved from local node...");

      // IIdentity currentNode = commMngr.getIdManager().getThisNetworkNode();

      if (!myNode && !myCIS) {

        if (logger.isDebugEnabled())
          logger.debug("Attempting to retrieve services from remote node: " + node.getJid());

        ServiceDiscoveryRemoteClient callback = new ServiceDiscoveryRemoteClient();
        getServiceDiscoveryRemote().getServices(node, callback);
        serviceList = callback.getResultList();
      }
    }

    // Quick log message
    if (logger.isDebugEnabled()) {

      if (serviceList.isEmpty()) logger.debug("getServices: no services found!");
      else {
        Iterator<Service> it = serviceList.iterator();
        String logStuff = "getServices: ";

        while (it.hasNext()) {
          logStuff += it.next().getServiceName() + "; \n";
        }

        logger.debug(logStuff);
      }
    }

    return new AsyncResult<List<Service>>(serviceList);
  }