Hi Hazelcast gurus,
I am trying to “offer” a string value into a Queue using a REST client and take() it from within a running java client.
With offer() and take() both in java, it works fine.
Exception I get in the blocking java client is:
Exception in thread "main" java.lang.ClassCastException: com.hazelcast.impl.ascii.rest.RestValue cannot be cast to java.lang.String
at com.mhfi.notification.distribution.NotifTestClient.main(NotifTestClient.java:23)
The java client code that is blocking on the queue is:
public static void main(String[] args) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.addAddress("127.0.0.1:5701");
HazelcastClient client = HazelcastClient.newHazelcastClient(clientConfig);
IQueue<String> queue = client.getQueue("MyQueue");
System.out.println("Queue size: " + queue.size());
try {
for(;;) {
String qItem = queue.take();
System.out.println("Queue item: " + qItem);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The server sets up the queue like so:
IQueue<String> queue = hInst.getQueue("MyQueue");
queue.offer("Hello");
queue.offer("World");
System.out.println("Queue size: " + queue.size());
I am sending the REST request from chrome using the REST plugin as follows:
URL: http://localhost:5701/hazelcast/rest/queues/MyQueue
Method: POST
Headers: Content-Type: text/plain
Data: “HelloZZZ”
What am I doing wrong? Your help is really appreciated.
regards
- sudarshan
S&P Capital IQ Architecture
Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
Here’s another observation – I am using Hazelcast v2.5:
Using REST for both ways works – ie - POST into Queue and GET from queue.
… the docs say use “You can offer a new item into the queue via HTTP POST and take and item from the queue via HTTP DELETE.”
If I do a HTTP DELETE, the server throws this exception (all inside Hazelcast) :
WARNING: [10.143.3.178]:5701 [dev] String index out of range: -24
java.lang.StringIndexOutOfBoundsException: String index out of range: -24
at java.lang.String.substring(String.java:1911)
at com.hazelcast.impl.ascii.rest.HttpDeleteCommandProcessor.handle(HttpDeleteCommandProcessor.java:40)
at com.hazelcast.impl.ascii.rest.HttpDeleteCommandProcessor.handle(HttpDeleteCommandProcessor.java:22)
at com.hazelcast.impl.ascii.TextCommandServiceImpl$CommandExecutor.run(TextCommandServiceImpl.java:198)
at com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:212)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
at com.hazelcast.impl.ExecutorThreadFactory$1.run(ExecutorThreadFactory.java:38)
Ok, I solved the original problem re: the ClassCastException this way, after getting a cue from googlegroups.
IQueue<RestValue> qRest = client.getQueue("MyQueue");
RestValue restValue = qRest.take();
byte[] postedBytes = restValue.getValue();
System.out.println(new String(postedBytes, "UTF-8"));
But the same queue “MyQueue” cannot now be used for both java clients as well as REST clients.
Now the java client throws the ClasscastException L
Is there a better way to do this w/o resorting to instanceOf or similar ?
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.