Home Help Center

IceGrid replication

IgorIgor Member Igor TkachevOrganization: Deutsche BankProject: financial tools
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.
<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"?
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 [email protected]:
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("[email protected]");
		
		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
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

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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>:
    <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
  • IgorIgor Member Igor TkachevOrganization: Deutsche BankProject: financial tools
    Hi Bernard!
    It seems you are right. The problem is with server start.
    if start.cmd looks like this:
    java -classpath D:/ice/lib/Ice.jar;D:/ice/out test.CalcService
    
    server just didn't start.

    if I add server.cfg as config:
    java -classpath D:/ice/lib/Ice.jar;D:/ice/out test.CalcService --Ice.Config=D:/ice/server.cfg
    
    where server.cfg is
    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?
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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
  • IgorIgor Member Igor TkachevOrganization: Deutsche BankProject: financial tools
    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:
    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
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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:
    <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
  • IgorIgor Member Igor TkachevOrganization: Deutsche BankProject: financial tools
    Hi Bernard!
    I managed to get it working! you are right again. Changing to direct call of java with options fixed the problem.
    <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!
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Igor,

    Good to hear you figured it out!

    All the best,
    Bernard
Sign In or Register to comment.