001: /*
002: * DDS (Data Distribution Service) for JacORB
003: *
004: * Copyright (C) 2005 , Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad
005: * allaoui <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Library General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: *
022: * Coontact: Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad allaoui
023: * <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
024: * Contributor(s)
025: *
026: **/
027:
028: package demo.dds.dcps;
029:
030: import org.jacorb.dds.DomainParticipantFactoryImpl;
031: import org.omg.CORBA.ORB;
032: import org.omg.CosNaming.NameComponent;
033: import org.omg.CosNaming.NamingContextExt;
034: import org.omg.CosNaming.NamingContextExtHelper;
035: import org.omg.dds.DomainParticipantFactory;
036: import org.omg.dds.DomainParticipantFactoryHelper;
037: import org.omg.PortableServer.POA;
038: import org.omg.PortableServer.POAHelper;
039:
040: public class Server implements Runnable {
041:
042: String[] args;
043:
044: public static void main(String[] args) {
045: Server server = new Server();
046: server.setArgs(args);
047: new Thread(server).start();
048: }
049:
050: /**
051: *
052: */
053: public void run() {
054:
055: try {
056: ORB orb = ORB.init(args, null);
057: // get reference to rootpoa & activate the POAManager
058: POA poa = POAHelper.narrow(orb
059: .resolve_initial_references("RootPOA"));
060: poa.the_POAManager().activate();
061:
062: // get the root naming context
063: org.omg.CORBA.Object objRef = orb
064: .resolve_initial_references("NameService");
065: // Use NamingContextExt which is part of the Interoperable
066: // Naming Service (INS) specification.
067: NamingContextExt ncRef = NamingContextExtHelper
068: .narrow(objRef);
069: DomainParticipantFactoryImpl impl = new DomainParticipantFactoryImpl(
070: orb, poa);
071:
072: // get object reference from the servant (and implicitly register
073: // it)
074: org.omg.CORBA.Object oref = poa.servant_to_reference(impl);
075: DomainParticipantFactory ref = DomainParticipantFactoryHelper
076: .narrow(oref);
077:
078: if (ncRef != null) {
079: // bind the Object Reference in Naming
080: NameComponent path[] = ncRef
081: .to_name("DomainParticipantFactory");
082: ncRef.rebind(path, ref);
083: }
084: System.out.println("Server ready and waiting ...");
085: orb.run();
086: } catch (Exception e) {
087: System.out.println("e" + e);
088: e.printStackTrace();
089: }
090: }
091:
092: public void end() {
093: Thread.currentThread().destroy();
094: }
095:
096: /**
097: * @param args
098: * The args to set.
099: */
100: public void setArgs(String[] args) {
101: this.args = args;
102: }
103: }
|