Archived

This forum has been archived. Please start a new discussion on GitHub.

ServantLocator.locate not called. Client get Ice.ConnectRefused

My client proxy on doing the checked cast for the stringified proxy "WxReports/<some uuid>@lohe&quot; catches an Ice.ConnectionRefusedException.
Is this because I am using a servant locator so the servant does not exist yet?
If so, the manual does not show how to use the proxy to complete the request.
I believe that I have properly created the servant locator and registered it with the adapter so that the locate() method is called when the request comes in.
But the locate() method is never invoked. I have a breakpoint in the method that never gets hit.
The locate() code is stubbed right now, but I will flesh it out once I get past this issue.

I originally did this using indirect proxies thru IceGrid (and it worked) by creating a servant for each wx report and adding the servant to the adapter. I did not manipulate the Ice Id, but simply created a stringified proxy of the form <some uuid>@lohe based on the published Ice Id.

Pls provide tip as to proper implementation of the client-side call.
I am the first at the lab to experiment with servant locators.

Thank you,
Larry O'Heron
Laboratory for Laser Energetics.


// implementation of my servant locator
public class WxReportServantLocator : Ice.ServantLocator
{
public void deactivate(string category)
{
throw new NotImplementedException();
}
public void finished(Ice.Current curr, Ice.Object servant, object cookie)
{
Debug.Print(cookie.ToString());
}
public Ice.Object locate(Ice.Current curr, out object cookie)
{
Ice.Object obj = null;
cookie = "my cookie";
return obj;
}
}

// adapter creation & activation code in server thread in main
adapter = ic.createObjectAdapter("DefaultAdapter");
WxReportServantLocator wxReportServantLocator = new WxReportServantLocator();
adapter.addServantLocator (wxReportServantLocator, "WxReports");
adapter.activate();
mreThreadServant.WaitOne();


// client side method invoked by Ice as a result of Ice.Storm
// publishing the id
public void notifyReportAvailable(Ice.Identity id)
{
try
{
id.category = "WxReports";
string t = Ice.Util.identityToString(id);
Ice.ObjectPrx obj = ic.stringToProxy(t + "@lohe&quot;);
WxStationReportPrx proxy = WxStationReportPrxHelper.checkedCast(obj); // Ice.ConnectionRefusedException thrown here.
if (proxy == null)
{
txtMsgs.Text = "Null proxy" + Environment.NewLine + txtMsgs.Text;
}
else
{
WxReport report = proxy.getWxReport(id);
rcvWxReport(report);
}
}
catch (Ice.Exception ex)
{
Debug.Print(ex.ToString());
}
}

Comments

  • bernard
    bernard Jupiter, FL
    Hi Larry,

    ConnectionRefusedException means the Ice client runtime could not establish a connection to the target object (really: object adapter). A common cause is forgetting to activate the object adapter in your server code. (A firewall between your client and server could also be the culprit). Your servant locator is not a contributing factor here.

    Since you are using IceGrid [you have indirect proxies with "@lohe&quot;], the issue could also be the connection to the IceGrid registry; so double-check that Ice.Default.Locator is set properly in your client configuration.

    Once this is fixed, you will need to implement your servant locator. With your current stubbed code, if all works, you should get an Ice::ObjectNotExistException when making any invocation (since your locate implementation returns null).

    I would also recommend to pass proxies instead of IDs, and make your Slice operations more type-safe, i.e.
    // Slice
    void notifyReportAvailable(WxStationReport* prx);
    
    // Java
    public void notifyReportAvailable(WxStationReportPrx prx)
    {
       // No need to manufacture the proxy or checkedCast:
    
       WxReport report = prx.getWxReport(); // if needed, the servant locator or and/or servant can extract the target ID using current.id.
       rcvWxReport(report);
    }
    

    Naturally, the publisher would then build and send the proxy instead of the ID.

    Best regards,
    Bernard
  • <Bernard> ConnectionRefusedException means the Ice client runtime could not establish a connection to the target object (really: object adapter). A common cause is forgetting to activate the object adapter in your server code. (A firewall between your client and server could also be the culprit). Your servant locator is not a contributing factor here.
    <Larry> Concur that there is no connection to object adapter. In provided code example, adapter activation occurs immediately after servant locator additition. Re firewall, IceGrid and IceStorm and the server and the client are all running on the same pc.
    <Bernard> Since you are using IceGrid [you have indirect proxies with "@lohe&quot;], the issue could also be the connection to the IceGrid registry; so double-check that Ice.Default.Locator is set properly in your client configuration.
    <Larry> IceGrid config is correct. Servants added to adapter, e.g. as in the file dir example in the manual, are reachable.

    The same solution/project when used as per the file/directory example in the manual, that is servants for each node are created and added to the adapter, are available to the client thru indirect proxies. Your point about proxy vs ids is taken, but that should not be the issue here.

    Thanks,
    Larry O'Heron
  • bernard
    bernard Jupiter, FL
    Hi Larry,
    IceGrid config is correct. Servants added to adapter, e.g. as in the file dir example in the manual, are reachable.

    Are these servants using the same adapter (named DefaultAdapter), configured to use Adapter ID = lohe? Can you provide the IceGrid configuration for your server? (In XML).
    Your point about proxy vs ids is taken, but that should not be the issue here.

    Agreed, we need to first resolve this ConnectionRefused issue.

    You could also enable tracing in the server and the client (Ice.Trace.Network=1) to see exactly which port(s) the server is listening on and which connection is refused.

    Best regards,
    Bernard
  • Bernard,
    The object adapter was NOT configured with the expected value.

    I had in the server.config file:
    DefaultAdapter.AdapterId = lohe // indirect proxies of form something@lohe

    When I used IceGridAdapter and listed the adapters, I found the following entry:
    >>>adapter list
    lohe // indirect proxies of form something@lohe

    Therefore the checkedCast() using id1234@lohe for the indirect proxy did not reach an object adapter and the connection was refused.
    Hence the conclusion is that I can not place a comment on the same line as the property.

    Pls comment.

    Thanks,

    Larry O'Heron (Laboratory for Laser Energetics)


    bernard wrote: »
    Hi Larry,



    Are these servants using the same adapter (named DefaultAdapter), configured to use Adapter ID = lohe? Can you provide the IceGrid configuration for your server? (In XML).



    Agreed, we need to first resolve this ConnectionRefused issue.

    You could also enable tracing in the server and the client (Ice.Trace.Network=1) to see exactly which port(s) the server is listening on and which connection is refused.

    Best regards,
    Bernard
  • I should have entered the line in the server.config file as:

    DefaultAdapter.AdapterId = lohe # indirect proxy of form id1234@lohe

    Larry O'Heron
  • bernard
    bernard Jupiter, FL
    Hi Larry,

    Yes, the comment character for config files is '#' and not '//'.

    Also, it is possible but highly unusual to write your own config files for servers with indirect object adapters.

    Usually, the config files are generated by IceGrid, i.e.:

    - you use XML files or IceGrid Admin to describe your IceGrid deployment
    - IceGrid generates the configuration files for the corresponding servers
    - you later use IceGrid Admin / icegridadmin to monitor, start and stop these servers

    Best regards,
    Bernard
  • Bernard,

    Point taken. Only one of us so far has done as you describe. However, you did cover it at the excellent training you gave us.

    My next learning curve will be that.

    Thank you,

    Larry O