[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [xmlblaster] connecting
Thanks for explaination. Replies inline.
Michele Laghi wrote:
> Hi Kai,
> I think there is a missunderstanding:
>
> When you try to connect in failsafe mode (failsafe: register a
> I_ConnectionStateListener + retries=-1) you don't get an exception even
> if the server is not available.
I read that retries=-1 is default, isn't it? And I registered a
ConnectionStateListener. The code I provided is a bit simplified, but I
got an exception. Maybe my configuration is something missing for
failsafe mode!?
I tried the following:
ConnectQos qos = new ConnectQos(glob);
Address addressProp = new Address(glob);
addressProp.setDelay(4000L); // retry connecting every 4 sec
addressProp.setRetries(-1); // -1 == forever
addressProp.setPingInterval(0L); // switched off
qos.setAddress(addressProp);
ConnectReturnQos result = access.connect(qos, new CallBackListener());
But I got an exception!
> What happens is that the connection request is queued on the client side
> and the XmlBlasterAccess object creates a fake return qos for you. So
> under a client point of view you are connected (even if the physical low
> level connection is not established).
>
> So isConnected returns true because the connect message was (at least)
> safely queued on the client side and you are allowed to publish
> subscribe and so on (as you would be physically connected). The only
> feature you are not able to do is GET (see the table in the failsafe
> requirement).
>
> Once you connect you are connected. The Connection has several states:
>
> POLLING
> ALIVE
> DEAD
>
> so in your case isConnected() gives true, isPolling() gives also true
> and isAlive() gives false.
Sorry maybe I'm to stupid but in my case all of this functions return
false because the field XmlBlasterAccess.connectReturnQos is null!
> So try the following:
>
> make a connect (no need to loop in the catch)
> => you connection msg is queued
> start the xmlBlaster
> => your method reachedAlive(..) is invoked
> stop the xmlBlaster
> => your method reachedPolling() is invoked
>
> So if you really need the server for your work (in many use cases you
> don't need it) you would block in the thread making the connect and you
> would release that thread in your reachedAlive() method.
>
> Also see the second example in the requirement for more details.
Okay attached you will find my simple test program. I hope I got it
right. I use the client jar build with "build dist-client" and the
standalone server with default config.
import org.xmlBlaster.client.I_Callback;
import org.xmlBlaster.client.I_ConnectionStateListener;
import org.xmlBlaster.client.I_XmlBlasterAccess;
import org.xmlBlaster.client.key.UpdateKey;
import org.xmlBlaster.client.qos.ConnectQos;
import org.xmlBlaster.client.qos.ConnectReturnQos;
import org.xmlBlaster.client.qos.UpdateQos;
import org.xmlBlaster.util.EmbeddedXmlBlaster;
import org.xmlBlaster.util.Global;
import org.xmlBlaster.util.XmlBlasterException;
import org.xmlBlaster.util.dispatch.ConnectionStateEnum;
import org.xmlBlaster.util.qos.address.Address;
public class XmlBlasterAccessTest
{
class CallBackListener implements I_Callback
{
/*
* (non-Javadoc)
*
* at see org.xmlBlaster.client.I_Callback#update(java.lang.String,
* org.xmlBlaster.client.key.UpdateKey, byte[],
* org.xmlBlaster.client.qos.UpdateQos)
*/
public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) throws XmlBlasterException
{
// TODO update implementation
return null;
}
}
class ConnectionListener implements I_ConnectionStateListener
{
/*
* (non-Javadoc)
*
* at see org.xmlBlaster.client.I_ConnectionStateListener#reachedAlive(org.xmlBlaster.util.dispatch.ConnectionStateEnum,
* org.xmlBlaster.client.I_XmlBlasterAccess)
*/
public void reachedAlive(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
{
// TODO reachedAlive implementation
System.out.println("reachedAlive");
synchronized (XmlBlasterAccessTest.this)
{
XmlBlasterAccessTest.this.notify();
}
}
/*
* (non-Javadoc)
*
* at see org.xmlBlaster.client.I_ConnectionStateListener#reachedDead(org.xmlBlaster.util.dispatch.ConnectionStateEnum,
* org.xmlBlaster.client.I_XmlBlasterAccess)
*/
public void reachedDead(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
{
// TODO reachedDead implementation
System.out.println("reachedDead");
}
/*
* (non-Javadoc)
*
* at see org.xmlBlaster.client.I_ConnectionStateListener#reachedPolling(org.xmlBlaster.util.dispatch.ConnectionStateEnum,
* org.xmlBlaster.client.I_XmlBlasterAccess)
*/
public void reachedPolling(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
{
// TODO reachedPolling implementation
System.out.println("reachedPolling");
}
}
public static void main(String[] args)
{
XmlBlasterAccessTest test = new XmlBlasterAccessTest();
test.test();
}
I_XmlBlasterAccess access;
Global glob;
EmbeddedXmlBlaster server;
public void test()
{
glob = new Global();
access = glob.getXmlBlasterAccess();
access.registerConnectionListener(new ConnectionListener());
try
{
ConnectQos qos = new ConnectQos(glob);
Address addressProp = new Address(glob);
addressProp.setDelay(4000L); // retry connecting every 4 sec
addressProp.setRetries(-1); // -1 == forever
addressProp.setPingInterval(0L); // switched off
qos.setAddress(addressProp);
ConnectReturnQos result = access.connect(qos, new CallBackListener());
} catch (XmlBlasterException e)
{
e.printStackTrace();
}
boolean alive = access.isAlive();
boolean connected = access.isConnected();
boolean polling = access.isPolling();
if (!alive && connected && polling)
{
try
{
synchronized (this)
{
this.wait();
}
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
access.disconnect(null);
System.out.println("exit");
}
}