Package org.omg.CORBA

Examples of org.omg.CORBA.ORB


      String[] iors = assServer.start_server(servers);

      BitSet served = new BitSet();

      ORB orb = org.omg.CORBA.ORB.init(new String[ 0 ], null);

      // Make pause for the processes to start.
      try
        {
          Thread.sleep(500);
        }
      catch (InterruptedException ex)
        {
        }

      org.omg.CORBA.Object[] objects = new org.omg.CORBA.Object[ servers ];

      for (int i = 0; i < iors.length; i++)
        {
          objects [ i ] = orb.string_to_object(iors [ i ]);
        }

      int[] times = new int[ requests ];
      Random r = new Random();

      for (int i = 0; i < times.length; i++)
        {
          times [ i ] = r.nextInt(200) + 200;
          served.set(times [ i ]);
        }

      Request[] reqs = new Request[ requests ];

      // The server may limit number of the queued requests per
      // socket. We allow no more than 10 tasks per socket.
      int[] tasks = new int[ servers ];
      int rn;

      for (int i = 0; i < reqs.length; i++)
        {
          do
            {
              rn = r.nextInt(objects.length);
            }
          while (tasks [ rn ] > max_tasks);
          tasks [ rn ]++;

          // The object to handle the requrest is selected randomly.
          // The acceleration factor will be lower than the number
          // of the "parallelized objects". This is sufficient
          // as this is just a test, not a real distribute computing task.
          Request rq =
            objects [ rn ]._create_request(null, "sleep_and_return",
                                           orb.create_list(1), null
                                          );

          rq.set_return_type(orb.get_primitive_tc(TCKind.tk_long));
          rq.add_in_arg().insert_long(times [ i ]);
          reqs [ i ] = rq;
        }

      long started = System.currentTimeMillis();

      orb.send_multiple_requests_deferred(reqs);

      // Be sure the execution has returned correctly.
      assertTrue("Hangs on orb.send_multiple_requests_defferred",
                 System.currentTimeMillis() < started + 199
                );
      assertTrue("orb.send_multiple_requests_defferred:"+
                 "Cannot be ready immediately",
                 !orb.poll_next_response());

      for (int i = 0; i < reqs.length; i++)
        {
          try
            {
              Request a = orb.get_next_response();
              served.clear(a.result().value().extract_long());
            }
          catch (Exception ex)
            {
              ex.printStackTrace();
            }
        }

      // Check the acceleration factor.
      long done_in = System.currentTimeMillis() - started;

      long required = 0;
      for (int i = 0; i < times.length; i++)
        {
          required += times [ i ];
        }

      // Compute the acceleration factor * 100 %.
      int acceleration = (int) ((100 * required) / done_in);

      // With 20 virtual servers and the used algorithm, we should
      // expect at least five-fold acceleration.
      assertTrue("Parallel work is broken :" + acceleration, acceleration > 500);

      assertEquals("Not all tasks served", served.cardinality(), 0);

      // 2. Testing the Request methods.
      Request rq =
        objects [ 0 ]._create_request(null, "sleep_and_return",
                                      orb.create_list(1), null
                                     );

      rq.set_return_type(orb.get_primitive_tc(TCKind.tk_long));

      rq.add_in_arg().insert_long(200);

      long t = System.currentTimeMillis();
      rq.send_deferred();

      // Be sure the execution has returned correctly.
      assertTrue("Hangs on Request.send_defferred",
                 System.currentTimeMillis() < t + 199
                );
      assertTrue("Request.send_defferred:cannot be ready immediately",
                 !rq.poll_response());

      try
        {
          Thread.sleep(300);
        }
      catch (InterruptedException ex)
        {
        }

      assertTrue("Request.send_defferred:Must be ready now",
                 rq.poll_response());
      assertEquals("Request.send_defferred:Result must be ready",
                 rq.result().value().extract_long(), 200);

      orb.shutdown(true);
  }
View Full Code Here


{
  public void test(TestHarness harness)
  {
    // Start the server.
    // Initializing ORB/POA and server object
    final ORB server_orb = ORB.init(new String[ 0 ], null);

    rf11Servant servant = new rf11Servant();

    server_orb.connect(servant);

    // Writing stringified IOR to file specified by IORfilename
    String ior = server_orb.object_to_string(servant);

    new Thread()
      {
        public void run()
        {
          server_orb.run();
        }
      }.start();

    // Wait for 3 seconds for the server to start.
    try
      {
        Thread.sleep(3000);
      }
    catch (InterruptedException ex)
      {
      }

    // Start the client.
    ORB client_orb = ORB.init(new String[ 0 ], null);
    NEC_RF11 obj = rf11Helper.narrow(client_orb.string_to_object(ior));
    rf11Caller ccall = new rf11Caller();

    ccall.init(client_orb, obj);
    ccall.run_all(harness);

    // Test for the server messages
    Iterator iter = servant.error_messages.iterator();
    while (iter.hasNext())
      {
        harness.fail("Server side error: " + iter.next());
      }

    // Shutdown bot ORBs.
    server_orb.shutdown(false);
    client_orb.shutdown(false);
  }
View Full Code Here

  {
    h = harness;

    String[] args = new String[ 0 ];

    final ORB server_orb = ORB.init(args, null);

    mirror reflector = new mirror();
    server_orb.connect(reflector);

    new Thread()
      {
        public void run()
        {
          server_orb.run();
        }
      }.start();

    // Wait for 500 ms for the orb to start.
    try
      {
        Thread.sleep(500);
      }
    catch (InterruptedException ex)
      {
      }

    String ior = server_orb.object_to_string(reflector);

    // Instantiate another orb where this reflector will be a stub:
    ORB client_orb = ORB.init(args, null);

    org.omg.CORBA.Object object =
      (org.omg.CORBA.Object) client_orb.string_to_object(ior);

    Request r =
      object._create_request(null, "pass", server_orb.create_list(0), null);

    // Write the test values.
    r.add_in_arg().insert_octet((byte) 0x77);
    r.add_in_arg().insert_long(1);
    r.add_in_arg().insert_longlong(2);
    r.add_in_arg().insert_short((short) 3);
    r.add_in_arg().insert_string("[string 4]");
    r.add_in_arg().insert_double(45.689);
    r.add_in_arg().insert_octet((byte) 0xFE);

    // This will serve as EOF marker.
    r.add_in_arg().insert_octet((byte) 0xFF);

    // For the last parameter, the value is not set.
    r.set_return_type(server_orb.create_sequence_tc(0,
                                                    server_orb.get_primitive_tc(TCKind.tk_octet)
                                                   )
                     );

    r.invoke();

    byte[] reflection = OctetSeqHelper.extract(r.result().value());

    assertEquals("length", expected.length, reflection.length);

    for (int i = 0; i < reflection.length; i++)
      {
        if ((reflection [ i ] & 0xFF) != expected [ i ])
          fail("Mismatch [" + i + "] expected " +
               Integer.toHexString(expected [ i ]) + " actual " +
               Integer.toHexString(0xFF & reflection [ i ])
              );
      }

    client_orb.shutdown(false);
    server_orb.shutdown(false);

    client_orb.destroy();
    server_orb.destroy();
  }
View Full Code Here

  public static String[] start_server(int n)
  {
    try
      {
        // Create and initialize the ORB.
        final ORB orb = ORB.init(new String[0], null);

        String[] iors = new String[ n ];

        for (int i = 0; i < iors.length; i++)
          {
            // Create the servant and register it with the ORB.
            assServant tester = new assServant();
            orb.connect(tester);
            iors [ i ] = orb.object_to_string(tester);
          }

        new Thread()
          {
            public void run()
            {
              // Start the thread, serving the invocations from clients.
              orb.run();
            }
          }.start();

        return iors;
      }
View Full Code Here

public class Streams
  implements Testlet
{
  public void test(TestHarness h)
  {
    ORB orb = ORB.init(new String[ 0 ], null);
    Any an = orb.create_any();

    OutputStream out = an.create_output_stream();

    comServant object = new comServant();
    orb.connect(object);

    out.write_Object(object);

    IOR ior = IORHelper.read(out.create_input_stream());

    boolean ip = false;

    for (int i = 0; i < ior.profiles.length; i++)
      {
        if (ior.profiles [ i ].tag == TAG_INTERNET_IOP.value)
          {
            if (ip)
              h.fail("HR:One internet profile expected");
            ip = true;
            h.check(ior.profiles [ i ].profile_data.length > 0,
                    "HR:Internet profile data"
                   );
          }
      }
    h.check(ip, "HR:Internet profile present");

    h.check(object._is_a(ior.type_id), "HR id");
    h.check(ior.profiles.length > 0, "HR profiles");

    out = orb.create_any().create_output_stream();

    IORHelper.write(out, ior);

    org.omg.CORBA.Object obj = out.create_input_stream().read_Object();
View Full Code Here

          ucInitialiser.class.getName(),
          ucInitialiser.class.getName()
        );

        // Create and initialize the ORB
        final ORB orb = org.omg.CORBA.ORB.init(new String[ 0 ], initialisers);

        assertTrue("PreInit", ucInitialiser.preInit);
        assertTrue("PostInit", ucInitialiser.postInit);

        // Create the general communication servant and register it
        // with the ORB
        poa_Servant tester = new poa_Servant();

        POA rootPOA =
          POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        Object object = rootPOA.servant_to_reference(tester);

        // IOR must contain custom fragment, inserted by interceptor.
        // Sun 1.4 had a bug that was fixed in 1.5.
        String ior = orb.object_to_string(object);

        assertTrue("IOR custom component (bug in 1.4, fixed in 1.5)",
          ior.indexOf(
            "45257200000020000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
          ) > 0
        );

        // Create the forwarding target and register it
        // with the ORB
        poa_Servant forw = new poa_Servant();

        tester.theField(15);
        forw.theField(16);

        // Another orb without interceptors.
        final ORB orbf = ORB.init(new String[ 0 ], null);

        POA rootPOA2 =
          POAHelper.narrow(orbf.resolve_initial_references("RootPOA"));

        Object fobject = rootPOA2.servant_to_reference(forw);

        // Storing the IOR reference for general communication.
        fior = fobject;

        rootPOA.the_POAManager().activate();
        rootPOA2.the_POAManager().activate();

        // Intercepting server ready and waiting ...
        new Thread()
          {
            public void run()
            {
              // wait for invocations from clients
              orb.run();
            }
          }.start();

        new Thread()
          {
            public void run()
            {
              // wait for invocations from clients
              orbf.run();
            }
          }.start();

        // Make pause and do a local call.
        Thread.sleep(1000);

        // Saying local hello.
        poa_comTester Tester = poa_comTesterHelper.narrow(object);

        Any a0 = orb.create_any();
        a0.insert_string("Initial value for slot 0");

        Any a1 = orb.create_any();
        a1.insert_string("Initial value for slot 1");

        ORB orb2 = ORB.init(new String[ 0 ], initialisers);

        try
          {
            // Set the initial slot values.
            Current current =
              CurrentHelper.narrow(orb.resolve_initial_references("PICurrent"));
            Current current2 =
              CurrentHelper.narrow(orb2.resolve_initial_references("PICurrent"));

            current.set_slot(ucInitialiser.slot_0, a0);
            current.set_slot(ucInitialiser.slot_1, a1);

            current2.set_slot(ucInitialiser.slot_0, a0);
            current2.set_slot(ucInitialiser.slot_1, a1);
          }
        catch (Exception e)
          {
            fail("Exception " + e + " while setting slots.");
            e.printStackTrace();
          }

        String lHello = Tester.sayHello();

        // Saying remote hello.
        Object object2 = orb2.string_to_object(ior);

        poa_comTester Tester2 = poa_comTesterHelper.narrow(object2);

        String hello = Tester2.sayHello();

        assertEquals("Local and remote must return the same", lHello, hello);

        // Saying remote hello via DII.
        Request rq =
          Tester2._create_request(null, "sayHello", orb2.create_list(0),
            orb2.create_named_value("", orb.create_any(), 0)
          );
        rq.set_return_type(orb2.get_primitive_tc(TCKind.tk_string));

        rq.invoke();

        assertEquals("Remote Stub and DII call must return the same", hello,
          rq.return_value().extract_string()
        );

        // Saying local hello via DII.
        rq =
          Tester._create_request(null, "sayHello", orb2.create_list(0),
            orb2.create_named_value("", orb.create_any(), 0)
          );
        rq.set_return_type(orb2.get_primitive_tc(TCKind.tk_string));

        rq.invoke();

        assertEquals("Local Stub and DII call must return the same", hello,
          rq.return_value().extract_string()
        );

        // Throw remote system exception
        try
          {
            Tester2.throwException(-1);
            fail("BAD_OPERATION should be thrown");
          }
        catch (BAD_OPERATION ex)
          {
            assertEquals("Minor code", ex.minor, 456);
            assertEquals("Completion status", CompletionStatus.COMPLETED_YES,
              ex.completed
            );
          }

        // Throw remote user exception
        try
          {
            Tester2.throwException(24);
            fail("UserException should be thrown");
          }
        catch (ourUserException ex)
          {
            assertEquals("Custom field", ex.ourField, 24);
          }

        // Throw local system exception
        try
          {
            Tester.throwException(-1);
            fail("BAD_OPERATION should be thrown");
          }
        catch (BAD_OPERATION ex)
          {
            assertEquals("Minor code", ex.minor, 456);
            assertEquals("Completion status", CompletionStatus.COMPLETED_YES,
              ex.completed
            );
          }

        // Throw local user exception
        try
          {
            Tester.throwException(24);
            fail("UserException should be thrown");
          }
        catch (ourUserException ex)
          {
            assertEquals("Custom field", ex.ourField, 24);
          }

        // Remote server side interceptor throws an exception
        try
          {
            Tester2.passCharacters("", "");
            fail("INV_FLAG should be thrown");
          }
        catch (INV_FLAG ex)
          {
            assertEquals("Minor", 52, ex.minor);
            assertEquals("Completion status",
              CompletionStatus.COMPLETED_MAYBE, ex.completed
            );
          }

        // Local server side interceptor throws an exception
        try
          {
            Tester.passCharacters("", "");
            fail("INV_FLAG should be thrown");
          }
        catch (INV_FLAG ex)
          {
            assertEquals("Minor", 52, ex.minor);
            assertEquals("Completion status",
              CompletionStatus.COMPLETED_MAYBE, ex.completed
            );
          }

        assertEquals("Forwarding test, remote", 16, Tester2.theField());
        assertEquals("Forwarding test, local", 16, Tester.theField());

        assertEquals("Forwarding test, remote", 16, Tester2.theField());
        assertEquals("Forwarding test, local", 16, Tester.theField());

        // Destroy orbs:
        orb.destroy();
        orb2.destroy();
        orbf.destroy();

        assertTrue("Destroyed", ucClientRequestInterceptor.destroyed);
        assertTrue("Destroyed", ucIorInterceptor.destroyed);
        assertTrue("Destroyed", ucServerRequestInterceptor.destroyed);
View Full Code Here

  public void testIt()
  {
    java.util.Properties props = System.getProperties();

    ORB orb = ORB.init(new String[ 0 ], props);

    POA root = TestUtil.GetRootPOA(orb);
    POAManager manager = root.the_POAManager();
    try
      {
        manager.activate();
      }
    catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex)
      {
        fail(ex);
        throw new RuntimeException(ex);
      }

    uTestDefaultServant(orb, root, manager);
    uTestServantLocator(orb, root, manager);
    uTestServantActivator(orb, root, manager);

    orb.destroy();
  }
View Full Code Here

  {
    if (typeCode == null)
      {
        StructMember[] members = new StructMember[ 17 ];

        ORB orb = ORB.init();

        TypeCode t_member;
        t_member = orb.get_primitive_tc(TCKind.tk_short);
        members [ 0 ] = new StructMember("shortVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_ushort);
        members [ 1 ] = new StructMember("ushortVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_long);
        members [ 2 ] = new StructMember("longVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_ulong);
        members [ 3 ] = new StructMember("ulongVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_float);
        members [ 4 ] = new StructMember("floatVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_double);
        members [ 5 ] = new StructMember("doubleVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_boolean);
        members [ 6 ] = new StructMember("boolVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_char);
        members [ 7 ] = new StructMember("charVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_octet);
        members [ 8 ] = new StructMember("octetVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_any);
        members [ 9 ] = new StructMember("anyVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_TypeCode);
        members [ 10 ] = new StructMember("tcVal", t_member, null);
        t_member = ObjectHelper.type();
        members [ 11 ] = new StructMember("objectVal", t_member, null);
        t_member = orb.create_string_tc(0);
        members [ 12 ] = new StructMember("stringVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_longlong);
        members [ 13 ] = new StructMember("longlongVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_ulonglong);
        members [ 14 ] = new StructMember("ulonglongVal", t_member, null);
        t_member = orb.get_primitive_tc(TCKind.tk_wchar);
        members [ 15 ] = new StructMember("wcharVal", t_member, null);
        t_member = orb.create_wstring_tc(0);
        members [ 16 ] = new StructMember("wstringVal", t_member, null);
        typeCode =
          orb.create_struct_tc(TestStructHelper.id(), "TestStruct", members);
      }
    return typeCode;
  }
View Full Code Here

      Stack sRef = null;
      // The argument can look like
      // "corbaname::host:4001/#StackFactory"
      String corbaName = new String(args[0]);
      try{
          ORB orb = ORB.init(args, null);

          objRef = orb.string_to_object(corbaName);
          sfRef  = StackFactoryHelper.narrow(objRef);
          sRef   = sfRef.create_stack();

          sRef.push(4);
          sRef.push(7);
View Full Code Here

    public static ORB orb;

  public static void main(String args[]) throws Exception {

        // create and init the ORB
        ORB orb = ORB.init(args, null);

        // get the root naming context
        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
     
        NamingContextExt namingCtx = NamingContextExtHelper.narrow(objRef);
  
        // resolve the object reference
        String bankname = "swissbank";
View Full Code Here

TOP

Related Classes of org.omg.CORBA.ORB

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.