public static void main(String[] args) throws Exception {
    System.setProperty(
        "java.security.policy", System.getProperty("user.home") + "/jini/policy.all");

    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new SecurityManager());
      System.out.println("DynamicDownloadRmiClient.main() setting custom security manager");
    }

    LookupLocator lookup = new LookupLocator("jini://localhost:4160");

    ServiceRegistrar registrar = lookup.getRegistrar();

    // give the poor guys some time to lookup
    Thread.sleep(10);

    UserService userService =
        (UserService)
            registrar.lookup(
                new ServiceTemplate(
                    null,
                    new Class[] {UserService.class},
                    new Entry[] {new Name(UserService.class.getSimpleName())}));
    System.out.println("Getting current users from remote: " + userService.getCurrentUsers());

    BankAccountService bankAccountService =
        (BankAccountService)
            registrar.lookup(
                new ServiceTemplate(
                    null,
                    new Class[] {BankAccountService.class},
                    new Entry[] {new Name(BankAccountService.class.getSimpleName())}));
    System.out.println(
        "Creating bank account from remote, id: " + bankAccountService.createBankAccount("aaa"));
  }
Esempio n. 2
0
 /**
  * Get a pointer to the Jini Lookup Service. (See Jini documentation for more info).
  *
  * <p>The Jini Lookup Service URL is determined as follows:
  *
  * <p>If the System property <code>"jini.lookup.url"</code> is provided, its value is the Jini
  * Lookup Service URL.
  *
  * <p>Otherwise, the default URL is assumed to be <code>"jini://localhost"</code>
  *
  * @return a pointer to the Jini Lookup Service.
  */
 public static ServiceRegistrar getRegistrar()
     throws IOException, ClassNotFoundException, MalformedURLException {
   final String jurl = System.getProperty("jini.lookup.url", "jini://localhost");
   final LookupLocator lookup = new LookupLocator(jurl);
   final ServiceRegistrar registrar = lookup.getRegistrar();
   if (registrar instanceof Administrable) debug("Registry is administrable.");
   return registrar;
 }
Esempio n. 3
0
  public ClienteOlaMundo() {

    LookupLocator lookupLocator = null;
    ServiceRegistrar serviceRegistrar = null;

    System.setProperty("java.rmi.server.codebase", "http://localhost:8080/classes/");
    System.out.println("Mensagem = " + msg);

    // Procura LookupService e obtem Registrar
    try {
      lookupLocator = new LookupLocator("jini://localhost");
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    System.out.println("LUS port = " + lookupLocator.getPort());

    try {
      serviceRegistrar = lookupLocator.getRegistrar();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    Name name = new Name("Exemplo simples OlaMundo...");

    Entry[] entries = new Entry[] {name};
    Class<?>[] classes = {OlaMundo.class};

    ServiceTemplate serviceTemplate = new ServiceTemplate(null, classes, entries);
    ServiceMatches serviceMatches = null;
    try {
      serviceMatches = serviceRegistrar.lookup(serviceTemplate, 10);
    } catch (RemoteException e) {
      e.printStackTrace();
    }

    System.out.println("serviceMatches = " + serviceMatches.toString());
    ServiceItem[] items = serviceMatches.items;
    for (ServiceItem item : items) {
      System.out.println("item.service = " + item.service.toString());
      System.out.println(
          "item.service.getClass().getName() = " + item.service.getClass().getName());
      System.out.println("item.service.toString() = " + item.service.toString());
      OlaMundo olaMundo = (OlaMundo) item.service;

      System.out.println("Retornou: " + olaMundo.dizOla(msg));
    }
  }
  public TransactionManagerAccessor(String propFileName) {
    LookupLocator locator = null;
    ServiceRegistrar registrar = null;

    // Security manager

    try {
      System.setSecurityManager(new RMISecurityManager());
    } catch (Exception e) {
      e.printStackTrace();
    }

    // Get properties from property file

    initProperties(propFileName);

    try {
      // Get lookup service locator at "jini://hostname"
      // use default port and register of the locator
      locator = new LookupLocator(jiniURL);
      registrar = locator.getRegistrar();

      // Space name provided in property file
      ServiceTemplate template;
      // Specify the service requirement, array (length 1) of
      // instances of Class
      Class[] types = new Class[] {TransactionManager.class};
      template = new ServiceTemplate(null, types, null);

      // Get manager, 10 attempts!
      for (int i = 0; i < 10; i++) {
        Object obj = registrar.lookup(template);

        if (obj instanceof TransactionManager) {
          manager = (TransactionManager) obj;
          break;
        }
        System.out.println("BasicService. TransactionManager not " + "available. Trying again...");
        Thread.sleep(MAX_LOOKUP_WAIT);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 5
0
 public static String discoveryInfo(final ServiceElement element) {
   StringBuilder builder = new StringBuilder();
   builder.append("[groups: ");
   int i = 0;
   for (String group : element.getServiceBeanConfig().getGroups()) {
     if (i > 0) builder.append(", ");
     builder.append(group);
     i++;
   }
   if (element.getServiceBeanConfig().getLocators() != null
       && element.getServiceBeanConfig().getLocators().length > 0) {
     builder.append(", locators: ");
     i = 0;
     for (LookupLocator locator : element.getServiceBeanConfig().getLocators()) {
       if (i > 0) builder.append(", ");
       builder.append(locator.toString());
       i++;
     }
   }
   builder.append("]");
   return builder.toString();
 }