Package bean.client

Source Code of bean.client.HelloClient

/*
* Copyright 2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package bean.client;

import bean.Hello;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.lease.LeaseRenewalManager;
import net.jini.lookup.ServiceDiscoveryManager;

import java.rmi.RMISecurityManager;
import java.security.Permission;

public class HelloClient {
    /*
      * This is for ease of use, for the invocation of the example. When
      * deploying outside of the example, this should be removed
      */
    static {
        System.setSecurityManager(new RMISecurityManager() {
            public void checkPermission(Permission perm) {
            }
        });
    }

    public static void main(String[] args) throws Exception {
        Class[] classes = new Class[]{bean.Hello.class};
        ServiceTemplate tmpl = new ServiceTemplate(null, classes, null);
        LookupDiscoveryManager ldm =
                new LookupDiscoveryManager(LookupDiscoveryManager.ALL_GROUPS,
                                           null,
                                           null);
        System.out.println("Discovering Hello service ...");
        ServiceDiscoveryManager sdm =
                new ServiceDiscoveryManager(ldm, new LeaseRenewalManager());
        /* Wait no more then 10 seconds to discover the service */
        ServiceItem item = sdm.lookup(tmpl, null, 10000);
        if(item != null) {
            System.out.println("Discovered Hello service");
            Hello hello = (Hello)item.service;
            System.out.println("Invoking Hello service ...");
            String ret = hello.hello("Hello from Client");
            System.out.println("Received: "+ret+" from Hello service");
        } else {
            System.out.println("Hello service not discovered, make sure "+
                               "service is deployed");
        }
        sdm.terminate();
    }
}
TOP

Related Classes of bean.client.HelloClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.