What to use so Geode native client pool doesn't hang if no locator found - gemfire

If I turn off my Geode server and server locator, and then try and connect a client using:
PoolFactory poolFactory = PoolManager
.CreateFactory()
.SetSubscriptionEnabled(true)
.AddLocator(host, port);
if (PoolManager.Find("MyPool") == null)
p = poolFactory.Create("MyPool");
then the poolFactory.Create("MyPool") instruction simply hangs. What do I use to return the Create in this situation of no connection?
It ought to be something like DEFAULT_SOCKET_CONNECT_TIMEOUT in the Javadoc but that doesn't exist in the C# native client...
.SetFreeConnectionTimeout doesn't return either.
Thanks

I don't believe PoolFactory::Create makes any synchronous connections, so I can't explain why it hangs. As this issue would require more back and forth you should post your question on the users#geode.apache.org mailing list.

Related

WCF ServiceDebugBehavior IncludeExceptionDetailInFaults = true

I have a server/client WCF app with calls from client to server and callbacks from server to client.
I'm getting some kind of error when I try to do the callback.
But the info I get is useless, so they give you the tip to set the exception Detail In Faults to true to see more details.
I have this but I dont know how to include other behaviour since only 1 is allowed.
ServiceMetadataBehavior smb1 = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
// If not, add one
if (smb1 == null)
smb1 = new ServiceMetadataBehavior();
smb1.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb1);
I also want to let know the way I'm using the callbacks.
When the client calls the server, my function in the server does all the stuff I need and saves the channel:
callbacks = OperationContext.Current.GetCallbackChannel<IServiceCallbackContract>();
And then when I need to call the client from the server, I use that channel. BUT NOT IN THAT FUNCTION!
I thought this couldn't be done but I saw it in some examples.
So maybe I'm doing something wrong there too and you only can do the callback within the function in the server called from the client and which interface specifies the interface callback contract.
Finally got it working that way, just saved the channel and answered when I need in other function.

Restlet Java Framework - does Client need to be closed in some way?

I've just inherited some code that uses the Restlet framework - must admit I'd never even heard of it until now.
The pattern seems to be to do:
Request request = new Request(method, uri);
Client client = new Client(protocols);
Response response = client.handle(request);
but when I was debugging the code, I noticed quite a few daemon threads running. Is that normal? Should the code be closing the Client or something similar?
Thanks,
Paul
You should call client.stop() when you are done.

How to simulate an uncompleted Netty ChannelFuture

I'm using Netty to write a client application that sends UDP messages to a server. In short I'm using this piece of code to write the stream to the channel:
ChannelFuture future = channel.write(request, remoteInetSocketAddress);
future.awaitUninterruptibly(timeout);
if(!future.isDone()){
//abort logic
}
Everything works fine, but one thing: I'm unable to test the abort logic as I cannot make the write to fail - i.e. even if the server is down the future would be completed successfully. The write operation usually takes about 1 ms so setting very little timeout doesn't help too much.
I know the preffered way would be to use an asynch model instead of await() call, however for my scenario I need it to be synchronous and I need to be sure it get finnished at some point.
Does anyone know how could I simulate an uncompleted future?
Many thanks in advance!
MM
Depending on how your code is written you could use a mock framework such as mockito. If that is not possible, you can also use a "connected" UDP socket, i.e. a datagram socket that is bound to a local address. If you send to a bogus server you should get PortunreachableException or something similar.
Netty has a class FailedFuture that can be used for the purpose of this,
You can for example mock your class with tests that simulate the following:
ChannelFuture future;
if(ALWAYS_FAIL) {
future = channel.newFailedFuture(new Exception("I failed"));
else
future = channel.write(request, remoteInetSocketAddress);

Cannot implement long polling

if(isset($_GET['actionid']) && isset($_GET['profileid']))
{
$actionid = $_GET['actionid'];
$profileid = $_GET['profileid'];
$res = $database->news_poll($profileid,$actionid);
$k = 0;
while(!$NROW =$res->fetch_array())
{
usleep('50000000');
$res = $database->news_poll($profileid,$actionid);
}
$action = actiontype_encode($NROW,'0',$json,$encode,$database);
$data['action'] = $action;
echo json_encode($data);
}
this is my script for polling the server for new data.
but the working browser stops working only for my site. I guess the problem is that when a particular browser subscribes for the new data the connection is kept open so no further request can be made by the browser to same server. please explain if any problem.
If there is any way at all you can, I recommend setting yourself up with NodeJS and SocketIO for long polling. Your web server needs to keep a request open for every connected user, and that is more than Apache/PHP can handle for very long.
If that's not possible I recommend short polling, doing a normal ajax request every 3 seconds. That's not perfect but manageble.
I answered a similar question recently with more details.
Regardless of language I strongly advise against writing your own long polling server, unless you want that to be your project for a couple of years. I have been in a project that used a home grown long polling server written C and then re-written in Java, and it was not pretty.
I figured out the problem is that Apache serves multiple requests from a single client one at a time. So when a request is made to the long polling script at backend for new data that request hangs other requests from the same browser to the same server.
To overcome this drawback one needs to use node.js or tornado.

Apache MINA Java TCP Client-Server Communication

i want co communicate TCP client server communication using apache mina.
can anyone give the code ?
i cant find it in any were....
google is failed to find it.
i want to send and recieve text messages via mina .
so please help me....
It is very simple
on the server side
SocketConnectorConfig SOCKET_CONFIG = new SocketConnectorConfig();
IoFilter charsetFilter = new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("UTF-8")));
SOCKET_CONFIG.getFilterChain().addLast("codec", charsetFilter);
theIoAcceptor.bind(new InetSocketAddress(thePort),
new TriggerReceiverHandler();
here ioAcceptor is of type org.apache.mina.common.IoAcceptor you can instantiate it by using NioDatagramAcceptor
TriggerReceiverHandler is the class that handles the messages and session related events.
it needs to extend the IoHandlerAdapter.
This is for server. Similarly for client the only change is instead of IoAcceptor you use the IoConnector.
Here is an example, well explained too.
http://www.techbrainwave.com/?p=912