public static Intrepid create( IntrepidSetup setup )
throws IOException {
if ( setup == null ) setup = new IntrepidSetup();
IntrepidSPI spi = setup.getSPI();
if ( spi == null ) spi = new MINAIntrepidSPI();
ScheduledExecutor thread_pool = setup.getThreadPool();
if ( thread_pool == null ) {
thread_pool = SharedThreadPool.INSTANCE;
}
InetAddress server_address = setup.getServerAddress();
Integer server_port = setup.getServerPort();
AuthenticationHandler auth_handler = setup.getAuthHandler();
String vmid_hint = setup.getVMIDHint();
if ( vmid_hint == null ) {
if ( server_address != null ) vmid_hint = server_address.getHostAddress();
else {
try {
InetAddress local_host = InetAddress.getLocalHost();
if ( local_host != null ) {
vmid_hint = local_host.getHostAddress();
// Weed out silly IP's.
if ( vmid_hint.equals( "127.0.0.1" ) ) vmid_hint = null;
}
}
catch ( UnknownHostException ex ) {
// ignore
}
}
}
ListenerSupport<ConnectionListener,Void> connection_listeners =
ListenerSupportFactory.create( ConnectionListener.class, false );
if ( setup.getConnectionListener() != null ) {
connection_listeners.add( setup.getConnectionListener() );
}
ListenerSupport<PerformanceListener,Void> performance_listeners =
ListenerSupportFactory.create( PerformanceListener.class, false );
final PerformanceListener perf_listener = setup.getPerformanceListener();
if ( perf_listener != null ) {
performance_listeners.add( perf_listener );
}
VMID vmid = new VMID( UUID.randomUUID(), vmid_hint );
// Create handlers
LocalCallHandler local_handler =
new LocalCallHandler( vmid, performance_listeners.dispatch() );
RemoteCallHandler remote_handler = new RemoteCallHandler( spi, auth_handler,
local_handler, vmid, thread_pool, performance_listeners,
setup.getChannelAcceptor() );
// Init SPI
spi.init( server_address, server_port, vmid_hint, remote_handler,
connection_listeners.dispatch(), thread_pool, vmid,
ProxyInvocationHandler.DESERIALIZING_VMID, performance_listeners.dispatch(),
setup.getUnitTestHook() );
Intrepid instance = new Intrepid( spi, vmid, local_handler, remote_handler,