Results 1 to 8 of 8

Thread: IceGrid replication

  1. #1
    Igor is offline Registered User
    Name: Igor Tkachev
    Organization: Deutsche Bank
    Project: financial tools
    Join Date
    Jun 2011
    Posts
    4

    IceGrid replication

    Hi,

    I'm trying to run simple demo with adapter's replication. The problem is registering objects in adapters and name used for accessing objects.

    Code:
    <icegrid>
    	<application name="CalculatorApplication">
    
        <replica-group id="CalcReplica">
          <load-balancing type="random" n-replicas="3"/>
          <object identity="Calculator" type="::calc::Calculator"/>
        </replica-group>
    
        <server-template id="CalculatorServer">
          <parameter name="index"/>
          <server id="CalculatorServer-${index}" exe="D:/ice/start.cmd" activation="on-demand">
    
    				<adapter id="CalcAdapter${index}" endpoints="default" replica-group="CalcReplica">
    					<property name="Identity" value="Calculator"/>
    				</adapter>
    
    			</server>
        </server-template>
    		<node name="Node1">
          <server-instance template="CalculatorServer" index="1"/>
    			<server-instance template="CalculatorServer" index="2"/>
    			<server-instance template="CalculatorServer" index="3"/>
    		</node>
    		
    	</application>
    </icegrid>
    Is that correct to create adapter with name "CalcAdapter"?
    Code:
    public class CalcService extends Application{
    
    	@Override
    	public int run(String[] args) {
    		ObjectAdapter adapter = communicator().createObjectAdapter("CalcAdapter");
    		CalcImpl calcImpl = new CalcImpl();
    		adapter.add(calcImpl, Util.stringToIdentity("Calculator"));
    		adapter.activate();
    		communicator().waitForShutdown();
    		return 0;
    	}
    
    	public static void main(String[] args) {
    		new CalcService().main("CalculatorServer", args);
    	}
    	
    }
    As I understood from documentation I can access to object by Calculator@CalcReplica:
    Code:
    public class Client {
    
    	public static void main(String[] args) throws Exception {
    	  System.out.println("Starting client");
    		Communicator c = Util.initialize(args);
    		System.out.println("Requesting proxy");
    		ObjectPrx prx = c.stringToProxy("Calculator@CalcReplica");
    		
    		System.out.println("Casting to calculator");
    		CalculatorPrx calc = CalculatorPrxHelper.checkedCast(prx);
    		System.out.println("Printing results:");
    		System.out.println("\tversion=" + calc.calcVersion());
    		System.out.println("\tsubtr=" + calc.subtrack(1, 2));
    		System.out.println("\tsum=" + calc.sum(1.23498723, 32.209823));
    		System.out.println("\tmultiply=" + calc.multiply(Math.PI, 3.489));
    		System.out.println("\tdivide=" + calc.divide(Math.PI, Math.E));
    		System.out.println("Done");
    	}
    }
    but I get
    Code:
    D:\ice>java -classpath lib/Ice.jar;out test.Client --Ice.Config=client.cfg
    Starting client
    Requesting proxy
    Casting to calculator
    Exception in thread "main" Ice.NoEndpointException
        proxy = "Calculator -t @ CalcReplica"
            at IceInternal.ConnectRequestHandler.getConnection(ConnectRequestHandler.java:240)
            at IceInternal.ConnectRequestHandler.sendRequest(ConnectRequestHandler.java:138)
            at IceInternal.Outgoing.invoke(Outgoing.java:66)
            at Ice._ObjectDelM.ice_isA(_ObjectDelM.java:30)
            at Ice.ObjectPrxHelperBase.ice_isA(ObjectPrxHelperBase.java:111)
            at Ice.ObjectPrxHelperBase.ice_isA(ObjectPrxHelperBase.java:77)
            at calc.CalculatorPrxHelper.checkedCast(CalculatorPrxHelper.java:610)
            at test.Client.main(Client.java:15)
    Any help would be really appreciated!

    Thanks

  2. #2
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Igor,

    Welcome to our forums!

    Yes, this is a correct way to create an adapter named "CalcAdapter" in your server.

    However, strangely, your descriptor does not include the 'name' attribute (a mandatory attribute) for <adapter>:

    Code:
    <adapter id="CalcAdapter${index}" endpoints="default" replica-group="CalcReplica" 
             <property name="Identity" value="Calculator"/>
    </adapter>
    This should include name="CalcAdapter". Without a name attribute, IceGrid should actually reject your descriptor. Can you double-check?

    Then, assuming the name is correct and match, for your client to work, you want to make sure IceGrid successfully starts your server(s). There is a chance "D:/ice/start.cmd" does not start this server ... I'd suggest to use first an IceGrid node started in a command-prompt (as opposed to a Windows service), to see more easily what's happening.

    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  3. #3
    Igor is offline Registered User
    Name: Igor Tkachev
    Organization: Deutsche Bank
    Project: financial tools
    Join Date
    Jun 2011
    Posts
    4
    Hi Bernard!
    It seems you are right. The problem is with server start.
    if start.cmd looks like this:
    Code:
    java -classpath D:/ice/lib/Ice.jar;D:/ice/out test.CalcService
    server just didn't start.

    if I add server.cfg as config:
    Code:
    java -classpath D:/ice/lib/Ice.jar;D:/ice/out test.CalcService --Ice.Config=D:/ice/server.cfg
    where server.cfg is
    Code:
    CalcAdapter.Endpoints=tcp
    CalcAdapter.AdapterId=CalcAdapter
    Ice.Default.Locator=IceGrid/Locator:tcp -p 4061
    the service is being activated some time and then says "activation timed out".

    What's wrong with service or startup script?

  4. #4
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Igor,

    When you deploy a server with IceGrid, IceGrid generates a configuration file for your server, and when starting this server, the IceGrid node passes --Ice.Config=<path to generated server config file> to the server executable.

    So if you "server executable" does handle well this command-line option, the server won't work. You should not write and use your own server config file with an IceGrid deployment. See Using Deployment.

    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  5. #5
    Igor is offline Registered User
    Name: Igor Tkachev
    Organization: Deutsche Bank
    Project: financial tools
    Join Date
    Jun 2011
    Posts
    4
    Bernard,

    The last thing which is unclear for me is how to write server code. I have CalcImpl which extends _CalculatorDisp and expose a couple of simple functions.

    I write server class like this:
    Code:
    public class CalcService {
    
    	public static void main(String[] args) {
    	  Communicator c = Util.initialize(args);
    		ObjectAdapter adapter = c.createObjectAdapter("CalcAdapter");
    		CalcImpl calcImpl = new CalcImpl();
    		adapter.add(calcImpl, Util.stringToIdentity("Calculator"));
    		adapter.activate();
    		c.waitForShutdown();
    	}
    	
    }
    reason = "object adapter `CalcAdapter' requires configuration"


    I have no idea what's wrong.

    BTW If you could provide working demo example that would be great!

    Thank you

  6. #6
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Igor,

    Your server code looks fine. I suspect the only issue is the <exe> in your descriptor.

    My recommendation is do use directly 'java' like in our demos, for example, from the demoj\IceGrid\simple:

    Code:
    <icegrid>
    
      <application name="Simple">
    
        <server-template id="SimpleServer">
          <parameter name="index"/>
          <server id="SimpleServer-${index}" exe="java" activation="on-demand">
            <option>Server</option>
            <adapter name="Hello" endpoints="tcp">
              <object identity="hello-${index}" type="::Demo::Hello" property="Identity"/>
            </adapter>
          </server>
        </server-template>
    
        <node name="node1">
          <server-instance template="SimpleServer" index="1"/>
          <server-instance template="SimpleServer" index="2"/>
          <server-instance template="SimpleServer" index="3"/>
        </node>
    
      </application>
    
    </icegrid>
    You can use <env> in addition to <option> to set your environment, e.g. CLASSPATH. See the "Icebox" example in XML Reference.

    On Windows, as of Ice 3.4.1, these demos are in the demos.zip file in your Ice installation folder (C:\Program Files (x86)\ZeroC\Ice-3.4.1). You should unzip in a good location, like your Documents folder.

    (We've made them much easier to find in the upcoming 3.4.2 release)

    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  7. #7
    Igor is offline Registered User
    Name: Igor Tkachev
    Organization: Deutsche Bank
    Project: financial tools
    Join Date
    Jun 2011
    Posts
    4
    Hi Bernard!
    I managed to get it working! you are right again. Changing to direct call of java with options fixed the problem.

    Code:
    <server-template id="CalculatorServer">
          <parameter name="index"/>
          <server id="CalculatorServer-${index}" exe="java" activation="on-demand">
            <option>test.CalcService</option>
            <env>CLASSPATH=D:/ice/lib/Ice.jar;D:/ice/out;$CLASSPATH</env>
    				<adapter id="CalcAdapter${index}" name="CalcAdapter" endpoints="default" replica-group="CalcReplica">
    					<property name="Identity" value="Calculator"/>
    				</adapter>
    
    			</server>
        </server-template>
    And I also looked into demo example. I didn't specify locator service when start client. That's was the reason of "No endpoint exception".

    Thank you very much!

  8. #8
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Igor,

    Good to hear you figured it out!

    All the best,
    Bernard
    Bernard Normier
    ZeroC, Inc.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. iceGrid/simple demo with replication
    By prettyMan in forum Help Center
    Replies: 8
    Last Post: 06-10-2010, 04:32 PM
  2. IceGrid Replication
    By b33fc0d3 in forum Help Center
    Replies: 2
    Last Post: 07-30-2009, 06:33 PM
  3. Replies: 8
    Last Post: 04-08-2009, 05:49 PM
  4. Problem with replication in IceGrid
    By davidcr1983 in forum Help Center
    Replies: 3
    Last Post: 12-15-2006, 07:02 AM
  5. Replies: 0
    Last Post: 07-20-2006, 04:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •