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

📄 profile.java

📁 java实现的P2P多agent中间件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	
	//#APIDOC_EXCLUDE_END
	
	/**
	 * This constant is the key of the property whose value contains
	 * the name of the directory where all the files generated by JADE
	 * should be put. The defaul value is the current directory.
	 **/
	public static final String FILE_DIR = "file-dir";
	
	public static final String LOCALHOST_CONSTANT = "localhost";
	
	//#APIDOC_EXCLUDE_BEGIN
	
	/**
	 Obtain a reference to the platform <i>Service Manager</i>, with
	 which kernel-level services can be added and removed.
	 @return A <code>ServiceManager</code> object, representing the
	 platform service manager.
	 */
	protected abstract ServiceManager getServiceManager() throws ProfileException;
	
	/**
	 Obtain a reference to the platform <i>Service Finder</i>, with
	 which kernel-level services can be looked up.
	 @return A <code>ServiceFinder</code> object, representing the
	 platform service manager.
	 */
	protected abstract ServiceFinder getServiceFinder() throws ProfileException;
	
	/**
	 Obtain a reference to the container <i>Command Processor</i>,
	 which manages kernel-level commands dispatching them to the
	 proper platform services.
	 @return A <code>ServiceManager</code> object, representing the
	 platform service manager.
	 */
	protected abstract CommandProcessor getCommandProcessor() throws ProfileException;
	
	//#MIDP_EXCLUDE_BEGIN
	protected abstract MainContainerImpl getMain() throws ProfileException;
	//#MIDP_EXCLUDE_END
	
	/**
	 */
	protected abstract IMTPManager getIMTPManager() throws ProfileException;
	
	/**
	 */
	public abstract ResourceManager getResourceManager() throws ProfileException;

	//#APIDOC_EXCLUDE_END
	
	
	//#MIDP_EXCLUDE_BEGIN
	/**
	 * Retrieve the configuration properties as they were passed to this Profile object, i.e. without 
	 * internal initializations automatically performed by the Profile class. 
	 */
	public abstract Properties getBootProperties();
	//#MIDP_EXCLUDE_END
	
	/**
	 * Retrieve a String value from the configuration properties.
	 * If no parameter corresponding to the specified key is found,
	 * return the provided default.
	 * @param key The key identifying the parameter to be retrieved
	 * among the configuration properties.
	 * @param aDefault The value to return when there is no property
	 * set for the given key.
	 */
	public abstract String getParameter(String key, String aDefault);
	
	/**
	 * Retrieve a boolean value for a configuration property.  If no
	 * corresponding property is found or if its string value cannot
	 * be converted to a boolean one, a default value is returned.
	 * @param key The key identifying the parameter to be retrieved
	 * among the configuration properties.
	 * @param aDefault The value to return when there is no property
	 * set for the given key, or its value cannot be converted to a
	 * boolean value.
	 */
	public abstract boolean getBooleanProperty(String key, boolean aDefault);
	
	/**
	 * Retrieve a list of Specifiers from the configuration properties.
	 * Agents, MTPs and other items are specified among the configuration
	 * properties in this way.
	 * If no list of Specifiers corresponding to the specified key is found,
	 * an empty list is returned.
	 * @param key The key identifying the list of Specifires to be retrieved
	 * among the configuration properties.
	 */
	public abstract List getSpecifiers(String key) throws ProfileException;
	
	/**
	 * Assign the given value to the given property name.
	 *
	 * @param key is the property name
	 * @param value is the property value
	 *
	 */
	public abstract void setParameter(String key, String value);
	
	/**
	 * Assign the given value to the given property name.
	 *
	 * @param key is the property name
	 * @param value is the property value
	 *
	 */
	public abstract void setSpecifiers(String key, List value);
	
	
	public static String getDefaultNetworkName() {
		String host = LOCALHOST_CONSTANT;
		//#MIDP_EXCLUDE_BEGIN
		try {
			host = java.net.InetAddress.getLocalHost().getHostAddress(); 
			
			if ("127.0.0.1".equals(host)) {
				// Try with the name
				host = java.net.InetAddress.getLocalHost().getHostName();
			}
		}
		catch(Exception e) {
		}
		//#MIDP_EXCLUDE_END
		return host;
	}
	
	//#MIDP_EXCLUDE_BEGIN
	public static boolean isLocalHost(String host) {
		return compareHostNames(host, LOCALHOST_CONSTANT);
	    /* Check that the local-host is actually local
		if (LOCALHOST_CONSTANT.equalsIgnoreCase(host)) {
			return true;
		}
		
	    try {
	        InetAddress localHostAddrs[] = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
	        InetAddress hostAddrs[] = InetAddress.getAllByName(host);
	
	        // The trick here is to compare the InetAddress
	        // objects, not the strings since the one string might be a
	        // fully qualified Internet domain name for the host and the 
	        // other might be a simple name.  
	        // Example: myHost.hpl.hp.com and myHost might
	        // acutally be the same host even though the hostname strings do
	        // not match.  When the InetAddress objects are compared, the IP
	        // addresses will be compared.
	        int i = 0;
	        boolean isLocal = false;
	
	        while ((!isLocal) && (i < localHostAddrs.length)) {
	            int j = 0;
	
	            while ((!isLocal) && (j < hostAddrs.length)) {
	                isLocal = localHostAddrs[i].equals(hostAddrs[j]);
	
	                j++;
	            }
	
	            i++;
	        }
	        return isLocal;
	    } 
	    catch (UnknownHostException uhe) {
	    	// An unknown host is certainly false
	    	return false;
	    }*/
	}
	
	/**
	 * Compares two host names regardless of whether they include domain or not.
	 * Note: this method does not work if "localhost" is used as host name.
	 */
	public static boolean compareHostNames(String host1, String host2) {
		if (host1.equalsIgnoreCase(host2)) {
			return true;
		}

		try {
			if (host1.equalsIgnoreCase(LOCALHOST_CONSTANT)) {
				host1 = InetAddress.getLocalHost().getHostName();
			}
			if (host2 != null && host2.equalsIgnoreCase(LOCALHOST_CONSTANT)) {
				host2 = InetAddress.getLocalHost().getHostName();
			}

			InetAddress host1Addrs[] = InetAddress.getAllByName(host1);
			InetAddress host2Addrs[] = InetAddress.getAllByName(host2);

			// The trick here is to compare the InetAddress
			// objects, not the strings since the one string might be a
			// fully qualified Internet domain name for the host and the
			// other might be a simple name.
			// Example: myHost.hpl.hp.com and myHost might
			// acutally be the same host even though the hostname strings do
			// not match.  When the InetAddress objects are compared, the IP
			// addresses will be compared.
			int i = 0;
			boolean isEqual = false;

			while ((!isEqual) && (i < host1Addrs.length)) {
				int j = 0;

				while ((!isEqual) && (j < host2Addrs.length)) {
					isEqual = host1Addrs[i].equals(host2Addrs[j]);
					j++;
				}

				i++;
			}
			return isEqual;
		}
		catch (UnknownHostException uhe) {
			// If we can't retrieve the necessary information and the two strings are not the same,
			// we have no chance to make a correct comparison --> return false
			return false;
		}
	}
	//#MIDP_EXCLUDE_END
	
}

⌨️ 快捷键说明

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