org.apache.oodt.commons.ExecServerConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oodt-commons Show documentation
Show all versions of oodt-commons Show documentation
Apache OODT Common Utilities Project
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.oodt.commons;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import org.apache.oodt.commons.util.Documentable;
import org.apache.oodt.commons.util.XML;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/** Configuration for an EDA exec-server.
*
* @author Kelly
*/
public class ExecServerConfig extends Executable implements Documentable {
/** Create an exec-server configuration.
*
* @param className Name of the class to execute.
* @param objectKey Object key under which class will register.
* @param properties Properties for the server.
*/
public ExecServerConfig(String className, String objectKey, InetAddress preferredHost, Properties properties) {
this.className = className;
this.objectKey = objectKey;
this.preferredHost = preferredHost;
this.properties = properties;
}
/** Create an exec-server configuration.
*
* @param xml XML DOM description, must be an <execServer> element.
* @throws SAXException If xml is invalid.
* @throws UnknownHostException If the xml refers to an unknown host name.
*/
public ExecServerConfig(Node xml) throws SAXException, UnknownHostException {
properties = new Properties();
preferredHost = org.apache.oodt.commons.net.Net.getLoopbackAddress();
NodeList children = xml.getChildNodes();
className = XML.unwrappedText(children.item(0));
objectKey = XML.unwrappedText(children.item(1));
for (int i = 2; i < children.getLength(); ++i) {
Node child = children.item(i);
String name = child.getNodeName();
if ("host".equals(name)) {
preferredHost = InetAddress.getByName(XML.unwrappedText(children.item(2)));
} else if ("properties".equals(name)) {
Configuration.loadProperties(child, properties);
} else {
throw new SAXException("Unknown node " + name + " in exec server XML");
}
}
}
/** Create an exec-server configuration.
*
* @param xml Serialized XML description.
* @throws SAXException If we can't parse xml.
* @throws UnknownHostException If the xml refers to an unknown host name.
*/
public ExecServerConfig(String xml) throws SAXException, UnknownHostException {
this(XML.parse(xml).getDocumentElement());
}
protected String[] getCommandLine() {
String[] commandLine = new String[6 + properties.size()];
commandLine[0] = "java";
commandLine[1] = "-Xms" + initialHeap;
commandLine[2] = "-Xmx" + maxHeap;
int index = 3;
for (Map.Entry