Code Search for Developers
 
 
  

DiscoveryPacket.java from GridBlocks at Krugle


Show DiscoveryPacket.java syntax highlighted

/*
 * Copyright (c) 2005
 * Helsinki Institute of Physics
 * see LICENSE file for details
 *
 * DiscoveryPacket.java
 * Created on Aug 12, 2004
 */
package fi.hip.gb.net.discovery;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Container for information about the GBAgent server for discovering purposes. 
 * This container includes information such as the URL of the server, supported services,
 * and the time since the last response from the server.
 * 
 * @author Juho Karppinen
 */
public class DiscoveryPacket {
    /** URL for the service */
    private String serviceURL;
    
    /** last response from the server */
    private long lastResponse = 0l;
    
    /** a string array of supported agent services on this server */
    private AgentPacket[] agents = new AgentPacket[0];
    
    /** all JAR files installed into the server */
    private String[] jarURLs = new String[0];
    
    private static Log log = LogFactory.getLog(DiscoveryPacket.class);
    
    /**
     * Empty constructor needed for serialization
     */
    public DiscoveryPacket() {
    }
    
    /**
     * Creates new packet with server name
     * @param serviceURL the URL for the service
     */
    public DiscoveryPacket(String serviceURL) {
        this();
        this.serviceURL = serviceURL;
    }
    
    /**
     * Resets the last response time to current system time
     */
    public void resetResponseTime() {
        this.lastResponse = 0l;
    }
    
    /**
     * Gets the delta time when server last time responded to discovery 
     * query.
     * @return the time to last response in milliseconds
     */
    public long getLastResponse() {
        return this.lastResponse;
    }
    /**
     * Sets the delta time when server last time responded to discovery 
     * query.
     * @param lastResponse the time of last response in milliseconds
     */
    public void setLastResponse(long lastResponse) {
        this.lastResponse = lastResponse;
    }
    /**
     * Gets the URL of the service.
     * @return returns the serviceURL.
     */
    public String getServiceURL() {
        return this.serviceURL;
    }
    /**
     * Sets the URL of the service.
     * @param serviceURL URL to the service.
     */
    public void setServiceURL(String serviceURL) {
        this.serviceURL = serviceURL;
    }
    
    /**
     * Gets installed JAR files in the server.
     * This is the same method as {@link DiscoveryPacket#getJars()} but
     * returns array of URLs.
     * @throws MalformedURLException if jar path is not URL friendly.
     */
    public URL[] jars() throws MalformedURLException {
        URL[] jars = new URL[this.jarURLs.length];
        for(int i=0; i < this.jarURLs.length; i++) {
            jars[i] = new URL(this.jarURLs[i]);
        }
        return jars;
    }
    
    /**
     * Gets installed JAR files in the server.
     * This is the same method as {@link DiscoveryPacket#jars()} but
     * returns array of String.
     * @return returns an array of JAR urls
     */
    public String[] getJars() {
        return this.jarURLs;
    }
    /**
     * Sets installed JAR files in the server.
     * This is the same method as {@link DiscoveryPacket#jars(URL[])} but
     * array is type of Strings.
     * @param serviceURL URL to the service.
     */
    public void setJars(String[] jarURLs) {
        this.jarURLs = jarURLs;
    }
    /**
     * Sets installed JAR files in the server.
     * This is the same method as {@link DiscoveryPacket#setJars(String[])} but
     * array is type of URLs.
     */
    public void jars(URL[] jars) {
        this.jarURLs = new String[jars.length];
        for(int i=0; i < jars.length; i++) {
            this.jarURLs[i] = jars[i].toExternalForm();
        }
    }
    
    /**
     * Gets the list of supported agent services on the server.
     * @return returns a array of agent services
     */
    public AgentPacket[] getAgents() {
        return this.agents;
    }
    /**
     * Sets the list of supported agent services on the server.
     * @param agents a array of agent services
     */
    public void setAgents(AgentPacket[] agents) {
        this.agents = agents;
    }
}




See more files for this project here

GridBlocks

GridBlocks builds a grid application framework via easy-to-use building blocks in distributed environment. The framework offers components for Grid security, distributed storage, computing, and Portlet web interfaces.

Project homepage: http://sourceforge.net/projects/gridblocks
Programming language(s): Java,JSP,XML
License: other

  AgentPacket.java
  DiscoveryPacket.java
  DiscoveryService.java
  DiscoveryThread.java
  DiscoveryThreadMBean.java
  JAXR.java