- the weaving process of the Spring framework is performed at runtime.
- the Spring framework uses proxies to implement the aspect orientation. These proxies come in two flavors, either a JDK dynamic Proxy (?) or a CGLIB proxy (see the web site of CGLIB for this).
- no field point cut (use aspectJ for this)
- the spring AOP does not implement the complete AOP, but mainly the most important aspects of AOP needed for the Inversion of Control approach of the spring framework for enterprise applications
Friday, 11 January 2008
Spring Aspect Oriented Programming
Differences between JUnit 3.8 and JUnit 4
import static org.junit.Assert.*; in the import section of your test file. Moreover, from JUnit 4.0 on there are also method to compare arrays of objects.
Initialisation and cleaning: The initialisation and cleaning were performed using setUp() and tearDown() methods. In version 4.0, it is not possible anymore since the class does not extend TestCase. To solve this, new Annotations are used: @Before and @After. Note that there are also the annotations: @BeforeClass and @AfterClass which are the methods which are called before loading the class for test and after all the tests have been performed. Tests Tests are annotated using the @Test annotation and must also return void and may not have any parameters. These properties are checked at runtime and issue exceptions if these rules are not respected. Ignoring Tests It is possible to ignore a given test by using the @Ignore annotation before or after the @Test annotationPerforming Test One performs test using the following call: $
java –ea org.junit.runner.JUnitCore
where
is the java complete name of the test class. Timeouts It is also possible to use a Timeout parameter for the test methods Parametrised Tests It is also possible to apply the same test but with different parameters. For this, the annotation @Parameters may be used together with the class annotation @RunWith(Parameterized.class) Suite Like for the preceding version, there is also the possibility to use Suites of Tests. For this the annotations @RunWith(Suite.class) and @Suite.SuiteClasses({FirstTestClass.class, SecondTestClass.class}) The article I used to write this entry states the lack of support in IDE for the new JUnit 4.0 version. But I suppose that this changed in the latest versions of eclipse.
Maven
- validate : validate the project is correct and all necessary information is available
- compile : compile the source code of the project
- test : test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
- package : take the compiled code and package it in its distributable format, such as a JAR.
- integration-test : process and deploy the package if necessary into an environment where integration tests can be run
- verify : run any checks to verify the package is valid and meets quality criteria
- install : install the package into the local repository, for use as a dependency in other projects locally
- deploy : done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
$ mvn eclipse:eclipsewhich creates the .classpath and .project files necessary for an eclipse project. One of the very interesting feature of maven is the possibility of creating template projects to simplify the creation of whole projects. It allows for example the possibility to go in the direction of rails some how.
MBeans and JMX
- attributes about the state of the resource
- constructors to create instances of the resource
- operations which can be performed on the resources
- parameters necessary for constructors and operations
- notifications which are emitted by the resource
- Standard MBeans (they implement a very simple interface)
- Dynamic MBeans (the meta data is provided separately from the resource)
- Model MBeans (Model MBeans are dynamic MBeans with supplementary model information)
- Open MBeans (another type of MBean extending the OpenType class allowing extremely complex MBeans)
Behavioral Pattern
- Chain of responsability (a request goes through an ordered chain of potential Workers, the appropriate worker determines that he has to treat the request, in that way the requester does not need to know any thing about the receiver of the request)
- Command (a request is wrapped in to an object in order to allow the parametrisation, the queueing, logging or cancellation of the request)
- Interpreter ()
- Iterator (a mean of accessing sequentially the elements of a aggregate object without revealing its internal structure)
- Mediator (an object which encapsulate the way different object interact with each others)
- Memento (method to capture and externalise the structure of an object to restore it later)
- Observer (an object offers the possibility of registering a number of observers which are notified as soon as some state is reached)
- State (the behavior of an object is dependant on the internal state of the object )
- Strategy ( define a number of interchangeable algorithms which can be used for a variety of clients and situations)
- Template Method ( defines a super class which provides a skeleton of the different steps which have to be performed in an algorithm, the subclasses of this superclass implement specifically these parts)
- Visitor (define operation which have to be performed on some objects of a structure and store the code for this operation in a separate object)
Structural Patterns
- Adapter (a class or interface created in order to adapt an object for another implementation)
- Bridge (the abstraction is separated from the implementation of a classso that they can evolve independantly)
- Composite (structures are organised in tree structures in order to model part-whole relationships but still offer a somewhat similar mean of interaction)
- Decorator (supplementary functionalities are attached to an object dynamically)
- Facade (provide a higher level interface thus simplifying its use)
- Flyweight (in order to support a large amount of fine-grained objects resources are shared)
- Proxy (an object serving as surrogate for another object in order to simplify the control of the original object)
Creational Patterns
- Abstract factory (This provides an abstract way to ensure a common method of creation of objects, through an interface that all the factories have to implement)
- Builder (Creates an object which is specialisedin the construction of a complex from its representation)
- Factory Method (define an abstract method for creating object but let subclasses decide of the details of the implementation and instantiation)
- Prototype (objects are first created using a prototype instance which is copied in order to create new instances of this type)
- Singleton (a class may have only one instance, and some method to get this instance is clearly defined and unambiguous)
Design Patterns
- creational patterns
- structural patterns
- behavioral patterns
- Intent (succint description of the intent of the design pattern)
- Other Names (other names which have been given to this pattern)
- Motivation (gives a description of the type of problem for which this pattern can be used)
- Applicability (gives a summary of the main guidelines when to use the pattern)
- Structure (gives a UML description of the overall structure of the pattern)
- Participants ( a description of the main elements or classes used in the structure)
- Collaboration (describes how the elements are used in cooperation with the others)
- Consequences (the main consequences of the use of the pattern)
- Implementation (a description of how to implement the pattern in a sensible way)
- Sample Code ( some sample code of the use and of the implementation)
- Known Uses (some example where this pattern has been used effectively)
- Related Patterns ( explains the relation this pattern has to other patterns)
Thursday, 10 January 2008
Java NIO - Channels
Channels are the other most important part of the NIO API.
A channel is a communication channel, that is a pipe of data.
The Channel interface has two methods: isOpen() and close() ( the latter may throws an IOException). Most Channels are specified using Interfaces. For example, there is the InterruptibleChannel interface which is a marker interface specifying how the channel behaves when a thread accessing it is interrupted.
There are different types of Channels.
- ReadableByteChannel and WritableByteChannel (Interfaces which define how to read from or write in a channel using a ByteBuffer)
- GatheringByteChannel and ScatteringByteChannel (interfaces defining methods to read from or write to a channel using an array of ByteBuffers)
- InterruptibleChannel ( interface defining the behaviour of the channel when the thread using it is interrupted)
- FileChannel (class for the interaction with a Channel based on a File)
- SocketChannel and ServerSocketChannel, and DatagramChannel ( classes for the communication based on sockets)
ChannelsUtilityClass There is a Utility Class called java.nio.channels.Channels, which has a number of utility methods to convert between the old and the new API. There are two Channel creating methods: newChannel(InputStream) and newChannel(OutputStream) which return a ReadableByteChannel and a WritableByteChannel respectively, and there are the newInputStream(ReadableByteChannel ch) and newOutputStream(WriteableByteChannel ch) which return InputStream and OutputStream respectively. The same kind of methods exist also for Readers and Writers: newReader and newWriter methods return the appropriate classes.
FileChannel FileChannel have different facets. Using the utility class Channels we can open FileChannel instances. Note that Channels opened from InputStreams are only readable while Channels from OutputStreams are only writable.
A number of methods are important for FileChannels. The force() methods writes to the disk the data which is actually cached ( for performance reasons). The truncate() methods gives a way to cut off all the data which is further than a given data. The methods position() and positions(long positions) are methods to decide at which part of the file the Channel should go.
Pipe Another important class is the Pipe class in general it is a conduit through which data can only go in one direction. Each pipe has a SourceChannel and a SinkChannel. The information written in the SinkChannel (a WritableChannel) is then transmitted to the SourceChannel (a ReadableChannel).
MemoryMappedFiles This type of Buffer and Channels are a far reaching topic so we treat them separately. SocketChannels SocketChannels are also a separate topic so we treat them also separately. Locks The topics of locks will also be covered in its own entry.
Java NIO - Buffers
We will start the explanation of the Java NIO main classes by taking a look at buffers.
BuffersThe Buffers contain a fixed amount of data (obtained using the capacity() method). They have a number of useful methods, for example: mark, reset, clear, flip and rewind. mark remenbers a position to which on can come back by using reset.
Access methods for the buffers are the get() and put() methods (these can be absolute or relative, i.e either one specifies the position in the buffer to set or retrieve or one gets or retrieve the current element).
There are one type of Buffer for each of the main non Boolean primitive types ( plus one called the MappedByteBuffer used when using memory-mapped files). All these Buffer types are abstract but possess a factory for that type of Buffer in order to create one. Different methods exist for example in the case of a CharBuffer: allocate( int capacity), or wrap(char[] array ) which return CharBuffers either of the given capacity or containing the elements found in the array. Note: the changes to the underlying array will be seen in the buffer and vice versa. This type of buffer have a non direct access. In other words they have an array used to contain the data. using the method hasArray() allows you to check whether this Buffer is non direct or not.
A special case has to be explained that direct buffer are actually of type ByteBuffer and are created using the allocateDirect(in capacity) method. The ByteBuffer class also provides the possibility to create View Buffers. This allows the possibility of obtaining instances of other types of Buffers, e.g CharBuffer or IntBuffer without taking care of the problem of conversion. This is performed for example using the asCharBuffer() method.
Many methods of the Buffer classes return also buffer references. Thus you can perform sequence of actions on the buffer in a simple way. This is called invocation chaining.
Other methods can also create views on other buffers. These methods allow for example the duplication of a buffer (using the duplicate() method), its view as a read only buffer (using the asReadOnlyBuffer() method), or a view of only part of this buffer (using the slice()) method).
Java NIO - Intro
- buffers (they represent fixed size arrays of primitive data elements wrapped with supplementary state information)
- Channels (a model for a communiation connection)
- File locking and memory mapped files (provides classes for monitoring locking of files as well as the possibility of mapping files to memory thus improving the process)
- sockets (these classes provies new methods of interacting with network sockets)
- selectors (this allows the possibility to watch the status of different channels to monitor them more easily
- regular expressions (Perl like regular expressions for processing of Java)
- character sets (the mappings between characters and byte streams)
Models for Enterprise Architectures
- The Open Group Architecture Framework (TOGAF)
- Zachman Framework (IBM Framework from the 1980s, now claimed as a de facto world standard)
- Department of Defence Architectural Framework
- Federal Enterprise Architecture Framework (United States Office of Management and Budget Federal Enterprise Architecture)
- United Kingdom Ministry of Defence Architectural Framework
- AGATE (French Délégation Générale pour l'Armement Atelier de Gestion de l'ArchiTEcture des systèmes d'information et de communication)
GIT
Monday, 7 January 2008
Google Web Toolkit
- Interfaces for RPC Calls
- Integration with JUnit
- Lots of Widgets for GUI Design (similar to Swing in the way of its use
AJAX
- load pages more quickly through an asynchron loading of the page(i.e the whole page is not loaded immediately).
- depending on the actions of the user, appropriate data can be loaded without requiring the reloading of the page
StAX- Streaming API for XML in Java
A number a way exist to access XML Data from Java. The DOM and SAX API are the two most traditional ones. A new alternatives under the form of the Streaming API for XML. This explanation uses the informations found in this tutorial.
The principle behing this API it to give the programmer the control over the next element of the file to be treated. This simplifies things greatly when there are many elements.
There are mainly two sets of APIs with the StaX API: cursor and iterator APIs.
Cursor API
The cursor walks the documents one infoset element at a time and always forward. For this there are two interfaces: XMLStreamReader
and XMLStreamWriter. These interfaces are very similar to the SAX handlers.
The Iterator API works on the idea, that the XML documents can be seen as a sequence of Events. Each of these Events are of a given type: StartDocument, StartElement, Attribute, ....
Differences. First of all, there are some things that are possible with the Iterator API which are not possible with the Cursor API. However, with the cursor API the code tends to be smaller and more efficient.
For processing events pipelines or modifiying the event stream use the iterator API.
In general, it is preferable to use the Iterator API, since this API is more easily extensible, thus it probably requires less refactoring for future versions of the applications.
Use of StaX APIsThe use of the StaX APIs is performed using the XMLInputFactory
, XMLOutputFactory
and XMLEventFactory
classes. These factory classes are configured using the setProperty() method.
Sunday, 6 January 2008
JAXB
- write the classes of the objects which should be stored as XML files, or DOM nodes, etc...
- annotate them so that the corresonding schema can be generated
- generate content according to schema
- unmarshal the content (i.e load into content tree in Java)
- validate if required
- marshall, i.e export again as XML
Data Mining
- Pentaho (used to be called WEKA)
- Rapid Miner (used to be called YALE, some parts of the systems were using Weka)
- Orange