Neo4j java rest binding - java

I am trying to get more familiar with the java-rest-binding (https://github.com/neo4j/java-rest-binding).
My main question is what operations of the GraphDatabaseService supports.
For example I read here that GlobalGraphOperation are not supported, but the tests use them. I have the final release (2.0.1). In adittion to this I would like to know if there is a significant defference between
GraphDatabaseService gds = new RestGraphDatabase("http://localhost:7474/db/data");
and
RestAPI restAPI = new RestAPIFacade("http://localhost:7474/db/data");`
or it's the same way to connect to the neo4j server.

The java-rest-binding is a flaky abstraction over REST-Operations over the wire. Unless you have a really good reason to use it, I wouldn't use it.
What's your actual use-case that you want to solve?

Related

How can I get the enqueue and dequeue count for an ActiveMQ queue WITHIN my Java Spring app?

I have been scouring the internet for documentation on this and it's unbelievable how difficult it is to find. My goal is to create a REST endpoint where I can return queue details such as enqueue, dequeue, etc. counts for a custom dashboard I am making.
I keep seeing documentation such as this, this, and this, but I can't seem to figure out how to get these details in my actual program. I have gotten about as far as using the JMX GUI, but that really is not the direction I need to be going. Can anyone help me figure out how to get simple connection to a broker that will return these details? I really have tried to research this, but I have not been able to figure out a way to incorporate this information to my application in any meaningful away.
The way to monitor the broker is via the broker JMX endpionts and the management beans it exposes. Other means would be through the Jolokia REST API that exposes those same MBeans. One article showing how to use the Jolokia bits is here.
A brief example of using JMX with ActiveMQ is below.
// connection
String url = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(url));
MBeanServerConnection connection = connector.getMBeanServerConnection();
// get queue size
ObjectName nameConsumers = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=myqueue");
DestinationViewMBean mbView = MBeanServerInvocationHandler.newProxyInstance(connection, nameConsumers, DestinationViewMBean.class, true);
long queueSize = mbView.getQueueSize();

Is there a Java TThreadPoolServer with NonBlockingSocket in Apache Thrift?

I have tried TSimpleServer, THsHaServer and TThreadedSelectorSever but none of them worked for my use case where I need to scale. My server needs to receive lots of data but right now when I use the servers listed above the receive rate is 600KB which is very low when compare to other servers which can receive 6MB using one socket. I am bound by thrift and I need to find a way to get through!
Basically I have a service written in C++ and JAVA (same service written in two different languages) and we are trying to see which one has high throughput). with the C++ service we dont use any thrift server. we created our own non blocking server which uses one thread to accept the requests and passes it on to threadpool where the methods gets executed but with the Java service I tried TSimpleServer, THsHaServer and TThreadedSelectorSever and the performance was not great and when I run the profiler the one that seems to hotspot is the following method
org.apache.thrift.server.TNonblockingServer$SelectAcceptThread.run() 456
I have no idea what is going on underneath the thrift source code.
Benchmark results: C++ service 35K/sec(requests per seconds) and Java 2500/sec (request per second) Again they are executing the same methods, same service written in two different languages.
My code for one of the server is as follows. I have tried others as well as mentioned above but no peformance gain
TTransportFactory tTransportFactory = new TFramedTransport.Factory();
TNonblockingServerTransport tNonblockingServerTransport = new TNonblockingServerSocket(7911);
PersistenceService.AsyncProcessor<?> processor = getAsyncProcessor(serviceName);
Factory protocolFactory = new TBinaryProtocol.Factory(true, true);
THsHaServer.Args serverArgs = new THsHaServer.Args(tNonblockingServerTransport);
serverArgs.processor(processor);
serverArgs.transportFactory(tTransportFactory);
serverArgs.protocolFactory(protocolFactory);
TNonblockingServer tNonblockingServer = new THsHaServer(serverArgs);
System.out.println("Starting persistence server on port 7911 ...");
tNonblockingServer.serve();

Java Google datastore async calls

I do not want to block threads in my application and so I am wondering are calls to the the Google Datastore async? For example the docs show something like this to retrieve an entity:
// Key employeeKey = ...;
LookupRequest request = LookupRequest.newBuilder().addKey(employeeKey).build();
LookupResponse response = datastore.lookup(request);
if (response.getMissingCount() == 1) {
throw new RuntimeException("entity not found");
}
Entity employee = response.getFound(0).getEntity();
This does not look like an async call to me, so it is possible to make aysnc calls to the database in Java? I noticed App engine has some libraries for async calls in its Java API, but I am not using appengine, I will be calling the datastore from my own instances. As well, if there is an async library can I test it on my local server (for example app engine's async library I could not find a way to set it up to use my local server for example I this library can't get my environment variables).
In your shoes, I'd give a try to Spotify's open-source Asynchronous Google Datastore Client -- I have not personally tried it, but it appears to meet all of your requirements, including being able to test on your local server. Please give it a try and let us all know how well it meets your needs, so we can all benefit and learn -- thanks!

Matlabcontrol: isExistingSession vs. setUsePreviouslyControlledSession

I've made a web service using Java 7 and Matlabcontrol-4.1.0. In this web service, i'm starting a Matlab r2015a session to execute a function. As far as I can see, isExistingSession and setUsePreviouslyControlledSession are functions to use a previously created session.
Q: In order to get the best performance, which method should I use?
isExistingSession (MatlabProxy) and/or setUsePreviouslyControlledSession (MatlabProxyFactoryOptions)?
I am using the following code at the moment:
// setting up connection to MatLab
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true).setHidden(true)
.setMatlabLocation(null).build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
I have checked setUsePreviouslyControlledSession and isExistingSession, but I don't quite understand.
After digging in the documentation, I think i've looked at it the wrong way.
setUsePreviouslyControlledSession (MatlabProxyFactoryOptions): sets whether to use a previously started session.
isExistingSession (MatlabProxy): Just returns a boolean answering "is there already a session running?".
These methods have different functions, so the comparison was never valid.

Error implementing the Thrift API

I'm implementing the Thrift Remote Procedure call framework in Java. I set up thrift and generated my skeleton code without a lot of issues, but now that I'm actually using the API methods, I get strange errors.
Here are the errors I get:
Exception in thread "main" org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:163)
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:91)
at SimonSays$Client.send_registerClient(SimonSays.java:102)
at SimonSays$Client.registerClient(SimonSays.java:96)
at simon.main(testClass.java:16)
I don't think I'm not making any mistakes, but just to make sure, here's the code that's leading to the errors:
TProtocol prot = new TBinaryProtocol(new TSocket("http://thriftpuzzle.facebook.com",9030));
SimonSays.Client client = new SimonSays.Client(prot);
client.registerClient("userEmailAddress#gmail.com");
The error is said to be generated from the client.registerClient() call, but that is a call to the code generated by Thrift, which makes me feel that I'm doing something wrong in setting up the connection itself.
The part about making a TProtocol instance I included myself, and it's likely that that's where the problem lies.
I was hoping that someone would have more of an idea about what's going wrong that I do.
Please let me know if more information or clarification is needed.
Edit: I found the TProtocol instantiation statement from the Cassandra Wiki
You need to call the open() method on your TSocket instance in order for it to connect and obtain the input/output streams it needs.
Source: TSocket.java

Categories