⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiniagentservice.java

📁 javaP2P技术内幕课程111213141516源代码
💻 JAVA
字号:
// These classes form the basis of the RMI support
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.io.IOException;

// We will require a number of Jini classes to support our Jini service
import net.jini.core.discovery.LookupLocator;
import net.jini.core.lookup.ServiceID;
import net.jini.discovery.DiscoveryGroupManagement;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.lookup.JoinManager;
import net.jini.lookup.ServiceIDListener;

//
// Extend the UnicastRemoteObject to create a non-activatable Jini service.
//

public class JiniAgentService extends UnicastRemoteObject
   implements Agent
{

   // The LookupDiscoveryManager you are using to find (request) LUSs
   private LookupDiscoveryManager lookupDiscMgr;

   // The lookup locator array that contains specific LUSs
   private LookupLocator locators[];

   // The groups array that contains specific groups, no groups, or all groups
   private String groups[] = DiscoveryGroupManagement.ALL_GROUPS;

   // The manager for joining LUSs
   private JoinManager joiner = null;

   // ServiceID returned from the lookup registration process
   private ServiceID serviceID = null;

   //
   // Add an init method to your constructor to do initialization specific to Jini.
   //

   public JiniAgentService() throws IOException {

   // call the UnicastRemoteObject to export the object
       super();

   // Initialize the Jini service
       init();
   }

   // Create a discovery manager by passing parameters
   // to discover all LUSes within the multicast radius.
   // Do this by specifying ALL_GROUPS and null parameters.

   private void init() throws IOException {
   
      try {
        lookupDiscMgr = new LookupDiscoveryManager(groups, locators, null);
      } catch (IOException e) {
        System.err.println("Problem starting discovery");
        e.printStackTrace();
             throw new IOException("Problem starting discovery:" +
                  e.getLocalizedMessage()); 
       }

       /* Register this service with any configured LUSes */
       if (serviceID == null) {
       // First instance ... need service id
          joiner = new JoinManager(
          this,                  // service object
          null,                  // service attributes 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -