Can a Java Object be a Response?

Poster Content
nk4um User
Posts: 7
November 27, 2007 18:03Thanks
PJR Thanks.  The other bit we needed was making sure the Aspect class of a sub request needed to be set. As somone new to NK the error message wasn''t supper clear, but we did figure it out.

- Peace
Like · Post Reply
nk4um Moderator
Posts: 901
November 27, 2007 08:59Resource Object Models
Hi djking,

As Tony said in NK3 the ROC model was new to people and we took the design decision to make it clear that a response from an accessor is a representation - it is therefore identified uniquely by URI and, consequently to be safe for shared access in cache, it should be immutable.

However nothing in the abstraction dictates what a representation should be.  Its very simple to create a new resource object model and have a set of accessors work with this object model.  For example for your Person here''s what you might have...


public class PersonAspect implements IAspectPerson
{   private String mName;
 
    public PersonAspect(String aName)
    {  mName=aName;
    }

    public String getName()
    {  return mName;
    }

    public void setName(String aName)
    {  mName=aName;
    }   

}


where the IAspectPerson interface would be...


public interface IAspectPerson extends IURAspect
{
   public String getName();
}


Here the PersonAspect can be any old POJO (or a container for POJOs).  However when used from another accessor then you''d always request the interface IAspectPerson eg...

person=context.sourceAspect("someURI", IAspectPerson.class);
person.getName();

The IURAspect derived interface should provide only the safe readonly methods -  or if necessary a cloned copy of the underlying objects.   It seems like extra work at first but it pays back in safety and global fine-grained caching performance.

There are several examples of resource models in the source code - for example take a look at the Pinky RSS/Atom feed library implemented on top of the Rome object model.  If you want to talk over your object model and how to represent it then let us know.

One useful rule of thumb.  Resources are generally sets of information and operations (accessors) are generally large scale - its a good idea to think of the resource object model as being quite coarse grained - for finer grained stuff you will want to stay down at the OO level.

Cheers,

Peter
Like · Post Reply
nk4um Administrator
Posts: 607
November 27, 2007 08:06NetKernel 4 / Aspects
Hi Djking,

NetKernel 4 is the project name for a long-term ground-up re-architect of NetKernel based on all the experience we''ve had of Resource Oriented Computing over the last few years. There is currently no hard release date for this project but it is expected that we''ll be starting an alpha programme around the middle of next year.

As such we continue to develop and support NetKernel 3.x. NetKernel 3.x has been hardened by a lot of production usage and has well rounded libraries. As such we''ll be recommending commercial use of NetKernel 3.x for quite some time to come.

To address the specific point of Aspects. The use of a specific empty IAspect interface in NetKernel 3.x is deliberate design decision. It forces the designer of new aspects to consider the differences between an aspect and an object. Aspects must be immutable at least in principle. This is an important principle that yields high returns in terms of thread-safety and caching.

In one line the definition of an aspect is:

An aspect is a snapshot of the state of a resource.

Hope this helps,
Tony
Like · Post Reply
nk4um User
Posts: 7
November 27, 2007 01:58Member Object
Let''s start simple, let''s say we have a Person class and I''d like to return a given Person from a URI.  How do I return an instance of Person as a representation from an Accessor?

- Peace

Like · Post Reply
nk4um Administrator
Posts: 158
November 27, 2007 01:04
There are many example Aspects in NetKernel.

If you can describe what you are trying to accomplish and I can provide better guidance to a particular one to help you get started.

Randy
Like · Post Reply
nk4um User
Posts: 7
November 27, 2007 00:40New Asspect?
There doesn''t seem to be any indication when 4.0 will be available to those outside the core team.

In 3.3 it looks like I need to define a new aspect, but it''s not clear as to where I would start that.  The base interface is just a marker interface, so it''s hard to know what rules apply.

I think this may be a deal breaker for us and NetKernel.

- Peace
Like · Post Reply
nk4um Administrator
Posts: 158
November 26, 2007 22:37Java Object as response representation
In NetKernel 3 (current version is 3.3) the representation returned is a Representation object which can reference one or more Aspects. If you have NetKernel running on your computer, this link brings up the page discussing this in detail:

http://localhost:1060/book/architectguide/doc_books_architect_mapping_java_objects

In NetKernel 4 you will be able to return any Java object in a response. Note carefully, however, that the ROC model is well defined only if the returned objects are treated as immutable value-objects.

So, in summary, in NetKernel 3 the implementation forces you to return an Aspect wrapping a Java object and in NetKernel 4 you will be able to return the Java object directly.

Like · Post Reply
nk4um User
Posts: 7
November 26, 2007 21:38Can a Java Object be a Response?
Is there such a thing as a JavaAspect that can be used to set Java Object as a response?  Or is this out side the scope of NK?

- Peace
Like · Post Reply