49 |
import gnu.CORBA.NamingService.NameParser; |
import gnu.CORBA.NamingService.NameParser; |
50 |
import gnu.CORBA.NamingService.NamingServiceTransient; |
import gnu.CORBA.NamingService.NamingServiceTransient; |
51 |
import gnu.CORBA.Poa.gnuForwardRequest; |
import gnu.CORBA.Poa.gnuForwardRequest; |
52 |
|
import gnu.CORBA.interfaces.gnuSocketFactory; |
53 |
|
|
54 |
import org.omg.CORBA.BAD_OPERATION; |
import org.omg.CORBA.BAD_OPERATION; |
55 |
import org.omg.CORBA.BAD_PARAM; |
import org.omg.CORBA.BAD_PARAM; |
136 |
setDaemon(true); |
setDaemon(true); |
137 |
try |
try |
138 |
{ |
{ |
139 |
service = new ServerSocket(s_port); |
service = socketFactory.createServerSocket(s_port); |
140 |
} |
} |
141 |
catch (IOException ex) |
catch (IOException ex) |
142 |
{ |
{ |
446 |
* exceeding this limit, the NO_RESOURCES is thrown back to the client. |
* exceeding this limit, the NO_RESOURCES is thrown back to the client. |
447 |
*/ |
*/ |
448 |
private int MAX_RUNNING_THREADS = 256; |
private int MAX_RUNNING_THREADS = 256; |
449 |
|
|
450 |
|
/** |
451 |
|
* The producer of the client and server sockets for this ORB. |
452 |
|
*/ |
453 |
|
public gnuSocketFactory socketFactory = DefaultSocketFactory.Singleton; |
454 |
|
|
455 |
/** |
/** |
456 |
* Create the instance of the Functional ORB. |
* Create the instance of the Functional ORB. |
513 |
{ |
{ |
514 |
Integer free = (Integer) freed_ports.getLast(); |
Integer free = (Integer) freed_ports.getLast(); |
515 |
freed_ports.removeLast(); |
freed_ports.removeLast(); |
516 |
s = new ServerSocket(free.intValue()); |
s = socketFactory.createServerSocket(free.intValue()); |
517 |
s.close(); |
s.close(); |
518 |
return free.intValue(); |
return free.intValue(); |
519 |
} |
} |
529 |
{ |
{ |
530 |
try |
try |
531 |
{ |
{ |
532 |
s = new ServerSocket(a_port); |
s = socketFactory.createServerSocket(a_port); |
533 |
s.close(); |
s.close(); |
534 |
Port = a_port + 1; |
Port = a_port + 1; |
535 |
return a_port; |
return a_port; |
543 |
Random rand = new Random(); |
Random rand = new Random(); |
544 |
// Try any random port in the interval RANDOM_PORT_FROM.RANDOM_PORT_TO. |
// Try any random port in the interval RANDOM_PORT_FROM.RANDOM_PORT_TO. |
545 |
int range = RANDOM_PORT_TO - RANDOM_PORT_FROM; |
int range = RANDOM_PORT_TO - RANDOM_PORT_FROM; |
546 |
|
IOException ioex = null; |
547 |
for (int i = 0; i < RANDOM_PORT_ATTEMPTS; i++) |
for (int i = 0; i < RANDOM_PORT_ATTEMPTS; i++) |
548 |
{ |
{ |
549 |
try |
try |
550 |
{ |
{ |
551 |
a_port = RANDOM_PORT_FROM |
a_port = RANDOM_PORT_FROM + rand.nextInt(range); |
552 |
+ rand.nextInt(range); |
s = socketFactory.createServerSocket(a_port); |
|
s = new ServerSocket(a_port); |
|
553 |
s.close(); |
s.close(); |
554 |
return a_port; |
return a_port; |
555 |
} |
} |
556 |
catch (IOException ex) |
catch (IOException ex) |
557 |
{ |
{ |
558 |
// Repeat the loop if this exception has been thrown. |
// Repeat the loop if this exception has been thrown. |
559 |
|
ioex = ex; |
560 |
} |
} |
561 |
} |
} |
562 |
|
|
563 |
try |
NO_RESOURCES bad = new NO_RESOURCES("Unable to open the server socket."); |
564 |
{ |
bad.minor = Minor.Ports; |
565 |
// Try the parameterless constructor. |
if (ioex != null) |
566 |
s = new ServerSocket(); |
bad.initCause(ioex); |
567 |
a_port = s.getLocalPort(); |
throw bad; |
|
s.close(); |
|
|
return a_port; |
|
|
} |
|
|
catch (IOException ex) |
|
|
{ |
|
|
NO_RESOURCES bad = new NO_RESOURCES("Unable to open the server socket."); |
|
|
bad.minor = Minor.Ports; |
|
|
bad.initCause(ex); |
|
|
throw bad; |
|
|
} |
|
568 |
} |
} |
569 |
|
|
570 |
/** |
/** |
573 |
* on this port first. It the port is busy, or if more objects are connected, |
* on this port first. It the port is busy, or if more objects are connected, |
574 |
* the subsequent object will receive a larger port values, skipping |
* the subsequent object will receive a larger port values, skipping |
575 |
* unavailable ports, if required. The change applies globally. |
* unavailable ports, if required. The change applies globally. |
576 |
* |
* |
577 |
* @param a_Port a port, on that the server is listening for requests. |
* @param a_Port a port, on that the server is listening for requests. |
578 |
*/ |
*/ |
579 |
public static void setPort(int a_Port) |
public static void setPort(int a_Port) |
1622 |
"'" |
"'" |
1623 |
); |
); |
1624 |
} |
} |
1625 |
|
|
1626 |
|
if (props.containsKey(gnuSocketFactory.PROPERTY)) |
1627 |
|
{ |
1628 |
|
String factory = null; |
1629 |
|
try |
1630 |
|
{ |
1631 |
|
factory = props.getProperty(gnuSocketFactory.PROPERTY); |
1632 |
|
if (factory!=null) |
1633 |
|
socketFactory = (gnuSocketFactory) |
1634 |
|
ObjectCreator.forName(factory).newInstance(); |
1635 |
|
} |
1636 |
|
catch (Exception ex) |
1637 |
|
{ |
1638 |
|
BAD_PARAM p = new BAD_PARAM("Bad socket factory "+factory); |
1639 |
|
p.initCause(ex); |
1640 |
|
throw p; |
1641 |
|
} |
1642 |
|
} |
1643 |
|
|
1644 |
Enumeration en = props.elements(); |
Enumeration en = props.elements(); |
1645 |
while (en.hasMoreElements()) |
while (en.hasMoreElements()) |
1646 |
{ |
{ |