Oracle Coherence A Netbeans Plug-in
By The Old Toxophilist on Nov 16, 2010
Recently I have been working with the Oracle Coherence product and noticed that when using the, recommended, POF Serialization functionality I seem to be writing a lot of similar code. When using POF Serialization you need to implement the PortableObject interface and write a readExternal and a writeExternal method which deserialize and serialize the class properties respectively.
Now this can become a bit tedious so to improve my NetBeans
development environment I decided to implement a some auto generation
functionality to take away the need to manually create these methods.
In addition to the generation of the POF methods I also implemented an
alternative that generates an Inner Serializer class and its associated
methods, as defined in Alek Soevic's book "Oracle
3.5", the final part of the plug-in is the ability to
create and run Coherence cluster nodes from within NetBeans. At
the moment I have built this plugin within NetBeans 6.9, but it runs
fine on 6.10, and it can be downloaded from the NetBean
The rest of this blog entry will describe the functionality provided
and how to create and configure a Coherence instance within Netbeans.
The Coherence Plugin
The Netbeans Coherence Plugin provides 3 key piece of functionality:
- Auto Generation of POF Serializer methods through an addition "Insert Code" Menu Option.
- Auto Generation of PofSerializer Inner Class through an addition "Insert Code" Menu Option.
- Ability to Create / Configure / Run Coherence Nodes through the
NetBeans Services Tab.
Using the Auto Generation from the "Insert Code" menu assumes you
have manually added the appropriate coherence.jar file to the projects
lib path through the normal NetBeans Methods whilst creating a new
server needs the user to define the Coherence Classpath property. The
functionality was implemented this way because I needed to create and
run bothe Coherence 3.5 and 3.6 nodes.
Insert Code Extensions
The insert code funtionality can be access by right-clicking on the
java code and following the installation of the plugin you will see a
menu something like the one below.
You will notice that their are now two Coherence Menu Items at the
top of the list (although sometimes you get one at the top and one at
the bottom) and I will briefly describe each and what effect they have
on the following same code.
Coherence POF Serializer Inner Class
On executing this menu option the lines 42 - 141 in the code example
below will be generated. The generated code implements a PofSerializer,
as an Inner Class, for the NewClass Class and this can be inserted /
references in the pof-config as defined by the example in line 69 - 81.
- Line 43 : Create a com.tangosol.util.Binary variable that will be used to retrieve and write the remainder information from the com.tangosol.io.pof.PofReader and com.tangosol.io.pof.PofWriter. This is added to prevent data loss in the case where the class has been manually edited elsewhere and additional information is being Serialized.
- Lines 57 - 67 : This new constructor is used to create an instance of the NewClass based on the deserialized information retrieved during a call the Inner Classes deserialize method.
- Lines 82 - 141 : Inner
Serializer Class which is referenced from the pof-config file. This
class defines a property (84 - 93) for all properties in the NewClass
that are not defined as transient, final or static because given their
nature these properties do not need to be serialized. The serialise
method, required by PofSerializer interface, can be seen in line 101 -
112 and simply takes the object passed in and accesses the appropriate
properties and writes then to the PofWriter. The deserialization is
done within the deserialize method defined in line 128 - 139 and it can
be seen that the properties are read into the local variables before
the NewClass constructor, defined in 57 - 67, is executed to return a
new object. Rather then use Magic number I have genrated a series of
constants, 114 - 121, for each of the fields to be serialized.
All these lines of code will be removed and regenerated if the
method is called again.
Coherence PortableObject Methods
Executing this functionality will generate the Simple POF Methods
define in lines 42 - 81 of the code below. In addition you can see that
the implements, line 21, has been extended to use the
- Line 21 : Add / append the com.tangosol.io.pof.PortableObject.
- Lines 47 - 56 : Simple readExternal, as mandated by PortableObject, which reads the lines from the PofReader and then assigns them to the appropriate properties. Again only the properties that need to be serialized and deserialized are used.
- Lines 58 - 65 : Index
- Lines 72 - 82 : Simple writeExternal method that takes the local properties and serializes them using the PofWriter.
Coherence Servers can be added to the new "Coherence Server" node
within the NetBeans Services Tab. This is done simply by right-clicking
on the node and selecting add server. At present this will allow the
user to simple name the server and then select ok. Once the server has
been created it will appear below the "Coherence Servers" Node as
can be seen in the image below. At this point the user should select
the properties for the new server and edit them to fit their
requirements. In this version the user has access to all the available
coherence properties and an additional to properties have been added
(Coherence Classpath and Additional Classpath) so that the user can
specify the locations of all appropriate jar files.
- Coherence Classpath : Intended to be used to specify the location of all the require Coherence jars
- Additional Classpath : Used to specify the location to any project specific jar files.
- Java Flags : Allows the user to specify additional Java flag, such as -Xms128m, that will written to the beginning of the run command.
- Custom Properties : This field allows the user to add custom
command line properties that will be written at the end of the command
line before the reference to the DefaultServer.
Once the server has been configured the new node provides a number
of options as part of the Right-Click Context Menu:
- Start : You can simply
run it by
selecting the Start menu option on the servers context menu and its
output will be written to the NetBeans Output window (below).
- Stop : This is only available for a running server and simplys stops its execution.
- Clone Server : Takes the current servers configuration and clones it allowing the user to specify a new name.
- Delete : Deletes the current server.
- Properties : Displays the server properties.
- Reset Coherence Properties
: Resets all the coherence Specific Properties for this server. That is
all properties that start tangosol..