Bazı örnekler şöyle
Enterprise JavaBeans (EJB) model - Java
Component Object Model (COM) - Microsoft
Common Object Request Broker Architecture (CORBA) - Object Management Group
Bileşen Nedir?
Bileşenin ne olduğunun tanımı bile kullanılan yönteme göre değişiyor. Benim gördüğüm bir örnek şöyle. - - Bileşen "server" denilen daha küçük parçacıklardan oluşuyor
- Her server kendi thread'i içinde çalışıyor. Yani tek thread'li
- Bileşen tüm server'ları grouplayan şey aslında. Bileşen start() veya stop() edilirse tüm server'lar birlikte çalışmaya başlıyor veya duruyor.
Corba
Corba'da bu server denilen şeylere "service" deniliyor. Şeklen şöyle. Facets sağlanan servisler. Receptacles kullanılan servisler. Event Sinks kullanılan olaylar. Event Sources oluşturulan olaylar.
General InterORB Protocol (GIOP)
Corba tarafından kullanılır. Aslında soyut bir protokol. Çeşitli ortamlara göre gerçekleştirimleri var.
Örnek
Server şöyle
try {
// create and initialize the ORB and POA
ORB orb = ORB.init(args, null);
POA poa = org.omg.PortableServer.POAHelper.narrow(
orb.resolve_initial_references(“RootPOA”));
// create servant and register it with the POA
HotelImpl servant = new HotelImpl(poa);
byte[] hotelId = poa.activate_object(servant);
// Get the Naming Service’s root naming context
org.omg.CORBA.Object obj = orb.resolve_initial_references(“NameService”);
NamingContextExt rootContext = NamingContextExtHelper.narrow(obj);
// Create a “Hotels” naming context
try {
rootContext.bind_new_context(rootContext.to_name(“Hotels”));
} catch (AlreadyBound e) {
//...
}
// Publish the Hotel’s object reference to the Naming Service
org.omg.CORBA.Object hotelObj = poa.id_to_reference(hotelId);
rootContext.rebind(rootContext.to_name(“Hotels / Hotel California”), hotelObj);
// activate the RootPOA, and run
poa.the_POAManager().activate();
orb.run();
} catch (org.omg.CORBA.SystemException ex) {
} catch (org.omg.CORBA.UserException ex) {
}Client şöyle
try {
// Initialize the ORB.
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
// Get the Naming Service’s root naming context
org.omg.CORBA.Object obj = orb.resolve_initial_references(“NameService”);
NamingContextExt rootContext = NamingContextExtHelper.narrow(obj);
// Get the Hotel’s object reference from the Naming Service
obj = rootContext.resolve_str(“Hotels / Hotel California”);
Hotel theHotel = HotelHelper.narrow(obj);
if (theHotel == null) {
...
}
...
} catch (org.omg.CORBA.SystemException ex)
} catch (org.omg.CORBA.UserException ex) {
}Örnek - Server
Şöyle yaparız
import org.omg.CORBA.*;import org.omg.PortableServer.*;//init ORBORB orb = ORB.init( args, null );// create a GoodDay objectGoodDayImpl goodDayImpl = new GoodDayImpl( args[0] );//init POAPOA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));poa.the_POAManager().activate();// create the object referenceorg.omg.CORBA.Object obj = poa.servant_to_reference( goodDayImpl );// print stringified object referenceSystem.out.println( orb.object_to_string( obj ) );// wait for requestsorb.run();
Örnek - Server
orbd, server ve client uygulamalarını çalıştırmak için şöyle yaparız
orbd -ORBInitialPort 1050 -ORBInitialHost localhost java Server -ORBInitialPort 1050 -ORBInitialHost localhost java Client -ORBInitialPort 1050 -ORBInitialHost localhost
Server başlatmak için şöyle yaparız. orbd'ye erişmek için gereki ayarlar args parametresi ile geçiliyor.
import EchoApp.Echo;
import EchoApp.EchoHelper;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
public class Server {
public static void main(String args[]) {
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get reference to rootpoa & activate the POAManager
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
// create servant
EchoServer server = new EchoServer();
// get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(server);
Echo href = EchoHelper.narrow(ref);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
NameComponent path[] = ncRef.to_name( "ECHO-SERVER" );
ncRef.rebind(path, href);
System.out.println("Server ready and waiting ...");
// wait for invocations from clients
orb.run();
} catch (Exception e) {...}
System.out.println("Exiting ...");
}
}Server bileşeni şöyledir
public class EchoServer extends EchoPOA {
@Override
public String echoString() {
return "Hello World!!!!!!!";
}
}
POA sınıfı şöyledir. Burada CORBA socketinden gelen verinin çağrılacak metod hakkında bilgi taşıdığı görülebilir.
/**
* EchoApp/EchoPOA.java .
* Generated by the IDL-to-Java compiler (portable), version "3.2"
* from Echo.idl
* Friday, June 29, 2018 4:29:11 PM EAT
*/
public abstract class EchoPOA extends org.omg.PortableServer.Servant
implements EchoApp.EchoOperations, org.omg.CORBA.portable.InvokeHandler
{
// Constructors
private static java.util.Hashtable _methods = new java.util.Hashtable ();
static
{
_methods.put ("echoString", new java.lang.Integer (0));
}
public org.omg.CORBA.portable.OutputStream _invoke (String $method,
org.omg.CORBA.portable.InputStream in,
org.omg.CORBA.portable.ResponseHandler $rh)
{
org.omg.CORBA.portable.OutputStream out = null;
java.lang.Integer __method = (java.lang.Integer)_methods.get ($method);
if (__method == null)
throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
switch (__method.intValue ())
{
case 0: // EchoApp/Echo/echoString
{
String $result = null;
$result = this.echoString ();
out = $rh.createReply();
out.write_string ($result);
break;
}
default:
throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
}
return out;
} // _invoke
// Type-specific CORBA::Object operations
private static String[] __ids = {
"IDL:EchoApp/Echo:1.0"};
public String[] _all_interfaces (org.omg.PortableServer.POA poa, byte[] objectId)
{
return (String[])__ids.clone ();
}
public Echo _this()
{
return EchoHelper.narrow(
super._this_object());
}
public Echo _this(org.omg.CORBA.ORB orb)
{
return EchoHelper.narrow(
super._this_object(orb));
}
} // class EchoPOA
Client başlatmak için şöyle yaparız. orbd'ye erişmek için gereki ayarlar args parametresi ile geçiliyor.
import EchoApp.Echo;
import EchoApp.EchoHelper;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;
public class Client {
public static void main(String args[]) {
try {
// create and initialize the ORB
ORB orb = ORB.init(args, null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
Echo href = EchoHelper.narrow(ncRef.resolve_str("ECHO-SERVER"));
String hello = href.echoString();
System.out.println(hello);
} catch (InvalidName invalidName) {
invalidName.printStackTrace();
} catch (CannotProceed cannotProceed) {
cannotProceed.printStackTrace();
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName invalidName) {
invalidName.printStackTrace();
} catch (NotFound notFound) {
notFound.printStackTrace();
}
}
}
Container
Tüm bileşen modellerinde, bileşen bir "container" içinde çalışır. Bu container işletim sisteminden yalıtım sağlar. Yani run-time sağlar. Container ile timer başlatılabilir. Container ile configürasyon okunur vs.

Hiç yorum yok:
Yorum Gönder