Wednesday, January 30, 2013

What else missing in java NIO

Java NIO2 in java 7 add important features to the NIO framework:
Finally we have good framework that handle files: http://docs.oracle.com/javase/tutorial/essential/io/fileio.html
and improvment of asynchronus chammels: http://www.ibm.com/developerworks/java/library/j-nio2-1/index.html

The reason that now the File framework is usefull is that in java NIO you are not have to support all the types of operating systems but only modern standard kind of desktop server OS. (today with the mobile revolution we can have all kind of OS not always with the same I/O features as windows and linux).
so we finally can copy files and handling directories and all kind of nice features.

Since we are no longer obligated to exotic OS i think it's about time to add interprocess communication in java NIO. so two processes in the same computer will be able to communicate without sockets.

why it is so important? today when we are going to the cloud and computer networks is very easy why spend time and add inter process communication? well i think it's important from the following reasons:
1. don't catch port for inter-process communication - let's say i have a multi process application on the same server - since java has GC sometimes for preformance issue you wish to seperate the application to several processes but still it can run on the same server. in this case if i can avoid catching port is for the best, becouse many time you need to handle issue like port is already taken by another application.

Second, we can add support of share memory that can be very useful in java applications. i know today you can use terracotta for that issue but it's much more complicated (you need teracotta server) here you get your service from the OS and it really simplify your application.

Third, security point of view, socket is a security risk if you can avoid it you reduce the security risk in your application. In addition, it can simplify integration with other languages like .NET since if we will get share memory with other languages communication can be easier.

public static void main(String[] args) throws IOException {
  Descriptor d = Descriptor.create("message");
  ProcessChannel proc = ProcessChannel.open(d);
  ByteBuffer buf = ByteBuffer.allocate(48);
  buf.clear();
  proc.receive(buf);
  ShareMemory s = ShareMemory.create(Descriptor.create("memory"),1000);
  OutputStream o = s.createOutputStream();
  ObjectOutputStream obj = new ObjectOutputStream(o);
  obj.writeObject(new Temp());
 }
So i really hope so java NIO will include such feature, what do you think?

No comments: