Exemplo n.º 1
0
 public static boolean findServiceLater(
     final ServiceBroker sb, final Class cl, final Object requestor, final Callback cb) {
   final Object req = (requestor == null ? ServiceFinder.class : requestor);
   if (sb.hasService(cl)) {
     Service s = (Service) sb.getService(req, cl, null);
     cb.foundService(s);
     return true;
   }
   ServiceAvailableListener sal =
       new ServiceAvailableListener() {
         public void serviceAvailable(ServiceAvailableEvent ae) {
           if (cl.isAssignableFrom(ae.getService())) {
             Service s = (Service) sb.getService(req, cl, null);
             cb.foundService(s);
             // sb.removeServiceListener(this);
           }
         }
       };
   sb.addServiceListener(sal);
   return false;
 }
  @Override
  public void load() {
    super.load();

    // we want the servlet service, but it's loaded after the MTS.
    // Also, we want the agent's proxy to the node-level
    // ServletService. The blackboard is loaded late enough, so we
    // wait 'til then...
    if (sb.hasService(BlackboardService.class)) {
      registerServlet();
    } else {
      ServiceAvailableListener sal =
          new ServiceAvailableListener() {
            public void serviceAvailable(ServiceAvailableEvent ae) {
              Class<?> cl = ae.getService();
              if (BlackboardService.class.isAssignableFrom(cl)) {
                registerServlet();
              }
            }
          };
      sb.addServiceListener(sal);
    }
  }