[xgws-dev] CVS Update: codes/xsoap/java/src/java/soaprmi/soaprpc/soaprmi/soaprpc
Aleksander Andrzej Slominski
xgws-dev_at_extreme.indiana.edu
Fri Oct 29 02:23:01 2004
aslom 04/10/29 02:22:51
Added: xsoap/java/src/java/soaprmi/soaprpc/soaprmi/soaprpc
TcpPortRange.java
Log:
added missing class required to support TCP port ranges to allow using of range of ports opened on firewall (adapted from CoG)
Revision Changes Path
1.1 codes/xsoap/java/src/java/soaprmi/soaprpc/soaprmi/soaprpc/TcpPortRange.java
Index: TcpPortRange.java
===================================================================
/* -*- mode: Java; c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
/*
* Copyright (c) 2002 Extreme! Lab, Indiana University. All rights reserved.
*
* This software is open source. See the bottom of this file for the licence.
*
* $Id: TcpPortRange.java,v 1.1 2004/10/29 07:22:51 aslom Exp $
*/
package soaprmi.soaprpc;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Map;
import soaprmi.ServerException;
import soaprmi.server.SoaprmiServerSocketFactory;
import soaprmi.util.logging.Logger;
/**
* This calss is copied from <a href="http://www.cogkit.org/">Cog</a> (see license notice attached at the end of file).
*
* @version $Revision: 1.1 $
* @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
*/
public class TcpPortRange {
private int minPort, maxPort;
private boolean portUsed[];
public TcpPortRange(String portRangeStr) {
init(portRangeStr);
}
private void init(String portRangeStr) {
if (portRangeStr == null) return ;
int pos = portRangeStr.indexOf("-");
if (pos == -1) {
throw new IllegalArgumentException("Missing dash in the port range property: " +
portRangeStr);
}
int min, max;
try {
min = Integer.parseInt(portRangeStr.substring(0, pos).trim());
} catch(Exception e) {
throw new IllegalArgumentException("The minimum port range value is invalid: " +
e.getMessage());
}
try {
max = Integer.parseInt(portRangeStr.substring(pos+1).trim());
} catch(Exception e) {
throw new IllegalArgumentException("The maximum port range value is invalid: " +
e.getMessage());
}
if (min >= max) {
throw new IllegalArgumentException("The minimum port range value is greater then " +
"the maximum port range value.");
}
minPort = min;
maxPort = max;
portUsed = new boolean[ maxPort-minPort ];
}
/**
* Returns first available port >= lastPortNumber;
*
* @param lastPortNumber port number to start finding the next
* available port from. Set it to 0 if
* called initialy.
* @return the next available port number from the lastPortNumber.
* @execption IOException if there is no more free ports available or
* if the lastPortNumber is incorrect.
*/
public int getFreePort(int lastPortNumber)
throws IOException
{
int id = 0;
if (lastPortNumber != 0) {
id = lastPortNumber - minPort;
if (id < 0) {
throw new IOException("Port number out of range.");
}
}
for(int i=id;i<portUsed.length;i++) {
if (portUsed[i]) continue;
return minPort+i;
}
throw new IOException("No free ports available.");
}
/**
* Sets the port number as used.
*
* @param portNumber port number
*/
public void setUsed(int portNumber) {
setPort(portNumber, true);
}
/**
* Releases or frees the port number.
* (Mark it as unused)
*
* @param portNumber port number
*/
public void free(int portNumber) {
setPort(portNumber, false);
}
private void setPort(int portNumber, boolean used) {
int id = portNumber - minPort;
if (id < 0) {
throw new IllegalArgumentException("Port number out of range: " + portNumber);
}
portUsed[id] = used;
}
}
/*
Globus Toolkit Public License (GTPL)
Copyright (c) 1999 University of Chicago and The University of
Southern California. All Rights Reserved.
1) The "Software", below, refers to the Globus Toolkit (in either
source-code, or binary form and accompanying documentation) and a
"work based on the Software" means a work based on either the
Software, on part of the Software, or on any derivative work of
the Software under copyright law: that is, a work containing all
or a portion of the Software either verbatim or with
modifications. Each licensee is addressed as "you" or "Licensee."
2) The University of Southern California and the University of
Chicago as Operator of Argonne National Laboratory are copyright
holders in the Software. The copyright holders and their third
party licensors hereby grant Licensee a royalty-free nonexclusive
license, subject to the limitations stated herein and
U.S. Government license rights.
3) A copy or copies of the Software may be given to others, if you
meet the following conditions:
a) Copies in source code must include the copyright notice and
this license.
b) Copies in binary form must include the copyright notice and
this license in the documentation and/or other materials
provided with the copy.
4) All advertising materials, journal articles and documentation
mentioning features derived from or use of the Software must
display the following acknowledgement:
"This product includes software developed by and/or derived from
the Globus project (http://www.globus.org/)."
In the event that the product being advertised includes an intact
Globus distribution (with copyright and license included) then
this clause is waived.
5) You are encouraged to package modifications to the Software
separately, as patches to the Software.
6) You may make modifications to the Software, however, if you
modify a copy or copies of the Software or any portion of it,
thus forming a work based on the Software, and give a copy or
copies of such work to others, either in source code or binary
form, you must meet the following conditions:
a) The Software must carry prominent notices stating that you
changed specified portions of the Software.
b) The Software must display the following acknowledgement:
"This product includes software developed by and/or derived
from the Globus Project (http://www.globus.org/) to which the
U.S. Government retains certain rights."
7) You may incorporate the Software or a modified version of the
Software into a commercial product, if you meet the following
conditions:
a) The commercial product or accompanying documentation must
display the following acknowledgment:
"This product includes software developed by and/or derived
from the Globus Project (http://www.globus.org/) to which the
U.S. Government retains a paid-up, nonexclusive, irrevocable
worldwide license to reproduce, prepare derivative works, and
perform publicly and display publicly."
b) The user of the commercial product must be given the following
notice:
"[Commercial product] was prepared, in part, as an account of
work sponsored by an agency of the United States Government.
Neither the United States, nor the University of Chicago, nor
University of Southern California, nor any contributors to
the Globus Project or Globus Toolkit nor any of their employees,
makes any warranty express or implied, or assumes any legal
liability or responsibility for the accuracy, completeness, or
usefulness of any information, apparatus, product, or process
disclosed, or represents that its use would not infringe
privately owned rights.
IN NO EVENT WILL THE UNITED STATES, THE UNIVERSITY OF CHICAGO
OR THE UNIVERSITY OF SOUTHERN CALIFORNIA OR ANY CONTRIBUTORS
TO THE GLOBUS PROJECT OR GLOBUS TOOLKIT BE LIABLE FOR ANY
DAMAGES, INCLUDING DIRECT, INCIDENTAL, SPECIAL, OR CONSEQUENTIAL
DAMAGES RESULTING FROM EXERCISE OF THIS LICENSE AGREEMENT OR
THE USE OF THE [COMMERCIAL PRODUCT]."
8) LICENSEE AGREES THAT THE EXPORT OF GOODS AND/OR TECHNICAL DATA
FROM THE UNITED STATES MAY REQUIRE SOME FORM OF EXPORT CONTROL
LICENSE FROM THE U.S. GOVERNMENT AND THAT FAILURE TO OBTAIN SUCH
EXPORT CONTROL LICENSE MAY RESULT IN CRIMINAL LIABILITY UNDER U.S.
LAWS.
9) Portions of the Software resulted from work developed under a
U.S. Government contract and are subject to the following license:
the Government is granted for itself and others acting on its
behalf a paid-up, nonexclusive, irrevocable worldwide license in
this computer software to reproduce, prepare derivative works, and
perform publicly and display publicly.
10) The Software was prepared, in part, as an account of work
sponsored by an agency of the United States Government. Neither
the United States, nor the University of Chicago, nor The
University of Southern California, nor any contributors to the
Globus Project or Globus Toolkit, nor any of their employees,
makes any warranty express or implied, or assumes any legal
liability or responsibility for the accuracy, completeness, or
usefulness of any information, apparatus, product, or process
disclosed, or represents that its use would not infringe privately
owned rights.
11) IN NO EVENT WILL THE UNITED STATES, THE UNIVERSITY OF CHICAGO OR
THE UNIVERSITY OF SOUTHERN CALIFORNIA OR ANY CONTRIBUTORS TO THE
GLOBUS PROJECT OR GLOBUS TOOLKIT BE LIABLE FOR ANY DAMAGES,
INCLUDING DIRECT, INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES
RESULTING FROM EXERCISE OF THIS LICENSE AGREEMENT OR THE USE OF
THE SOFTWARE.
END OF LICENSE
*/
/*
* Indiana University Extreme! Lab Software License, Version 1.2
*
* Copyright (C) 2002 The Trustees of Indiana University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1) All redistributions of source code must retain the above
* copyright notice, the list of authors in the original source
* code, this list of conditions and the disclaimer listed in this
* license;
*
* 2) All redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* listed in this license in the documentation and/or other
* materials provided with the distribution;
*
* 3) Any documentation included with all redistributions must include
* the following acknowledgement:
*
* "This product includes software developed by the Indiana
* University Extreme! Lab. For further information please visit
* http://www.extreme.indiana.edu/"
*
* Alternatively, this acknowledgment may appear in the software
* itself, and wherever such third-party acknowledgments normally
* appear.
*
* 4) The name "Indiana University" or "Indiana University
* Extreme! Lab" shall not be used to endorse or promote
* products derived from this software without prior written
* permission from Indiana University. For written permission,
* please contact http://www.extreme.indiana.edu/.
*
* 5) Products derived from this software may not use "Indiana
* University" name nor may "Indiana University" appear in their name,
* without prior written permission of the Indiana University.
*
* Indiana University provides no reassurances that the source code
* provided does not infringe the patent or any other intellectual
* property rights of any other entity. Indiana University disclaims any
* liability to any recipient for claims brought by any other entity
* based on infringement of intellectual property rights or otherwise.
*
* LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH
* NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA
* UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT
* SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR
* OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT
* SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP
* DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE
* RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS,
* AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING
* SOFTWARE.
*/