All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.globus.common.ResourceManagerContact Maven / Gradle / Ivy

/*
 * Copyright 1999-2010 University of Chicago
 *
 * 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 org.globus.common;

import java.util.StringTokenizer;

/**
 * The purpose of this class is to parse resource manager contact strings.
 * It can handle literal IPv6 addresses enclosed in square brackets 
 * ('[' and ']'). 
 */
public class ResourceManagerContact {
  
    public final static String DEFAULT_SERVICE = "/jobmanager";
    public final static int DEFAULT_PORT       = 2119;
    
    protected String hostName    = null;
    protected int portNumber     = -1;
    protected String serviceName = null;
    protected String globusDN   = null;

    /* just for the super classes */
    protected ResourceManagerContact() {
    }

    public ResourceManagerContact(String contact) {
	parse(contact);
    }

    protected void parse(String contact) {

	char c;
	int i;
	
	i = getHostToken(contact);
    
	if (i == -1) {
	    hostName = contact;
	    return;
	}

	hostName = contact.substring(0, i);
	c        = contact.charAt(i);
	
	if (c == '/') {
	    parseService(contact, i);
	} else {
	    
	    int j = getToken(contact, i+1);
	    if (j == -1) {
		portNumber = parsePort(contact.substring(i+1));
		return;
	    }

	    portNumber = parsePort(contact.substring(i+1, j));
	    c          = contact.charAt(j);

	    if (c == ':') {
		globusDN = contact.substring(j+1);
		return;
	    } else if (c == '/') {
		parseService(contact, j);
	    }
	}
    }

    private int parsePort(String port) {
	if (port.length() == 0) {
	    return DEFAULT_PORT;
	} else {
	    return Integer.parseInt(port);
	}
    }

    private void parseService(String contact, int from) {
	int pos = contact.indexOf(":", from);
	if (pos == -1) {
	    serviceName = contact.substring(from);
	} else {
	    serviceName = contact.substring(from, pos);
	    globusDN   = contact.substring(pos+1);
	}
    }

    private int getToken(String contact, int from) {
	int len = contact.length();
	char c;
	int i;
	
	for (i=from;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy