Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
interface Counter {
void increment ( in CounterCallback
cbref );
};
};
Servant
import CounterPackage.*;
public class Counter extends _CounterImplBase {
private int sum;
public Counter () {
sum = 0;
}
public void increment (CounterPackage.CounterCallback
cbref) {
sum ++;
cbref.callback (sum); // Notify client that
computation is complete
}
}
Server Unchanged
import org.omg.CORBA.*;
import java.io.*;
CounterPackage.Counter myCount =
CounterHelper.narrow (orb.string_to_object(args[0]));
myCount.increment(cbref);
}
}
Real Callbacks need Threads
• Servant
– increment method starts a new thread to do the
computation and the original thread returns immediately
– alternatively declare method as oneway
oneway void increment(in CounterCallback cbref);
• Client
– create CounterCallback in a separate thread with an
event loop
Initialisation
Namespace
Name Server
<name_1, object_1>
2 <name_2, object_2>
…
<name_n, object_n>
ORB
Client Server
bind name
to object
resolve 1
name
ORB 3 ORB
4
invoke service
Adding simple naming to the server
import org.omg.CosNaming.*;
org.omg.CORBA.Object objRef =
orb.resolve_initial_references ("NameService");
NamingContext ncRef = NamingContextHelper.narrow (objRef);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references ("NameService");
NamingContext ncRef = NamingContextHelper.narrow (objRef);
• Repository ID (standardized)
– Information about the interface the IOR represents (used by
DII and narrow)
• Endpoint Info (standardized)
– For the physical connection: IP and Port numbers
• Object Key (proprietary)
– Vendor dependent way the ORB (and OA) identify the
target object on the server
– Opaque to the client
IIOP
• Allows interoperability between different
ORB’s
• Precise specification of the on-the-wire
representation of data and messages for
TCP/IP