|
Using AnnotationsTerracotta configuration can normally be implemented by identifying classes in your application that need to be instrumented and locked using the appropriate XML in the tc-config.xml file. Annotations, however, provide a mechanism for developers to mark class instrumentation, root configuration, transient fields, and locking directly in your Java class files. One advantage to using Annotations is that the Terracotta definitions for your classes will stay with your code. Encapsulating all information about a class — including its Terracotta nature — in the class file improves the readability of your application. Also, refactoring annotated classes does not require changing the tc-config.xml file.
Installing TIM-AnnotationsTo use annotations, you will need the annotations TIM. This can installed in two ways:
To install automatically using the tim-get script use the following command: [PROMPT] tim-get.sh install tim-annotations Installing tim-annotations (1.2.0-SNAPSHOT) and dependencies... Skipped: modules-common (2.7.0-SNAPSHOT) Installed: tim-annotations (1.2.0-SNAPSHOT) Of course, your versions may differ, the versions listed above are for a pre-release version of Terracotta 2.7. Configuring Your Application To Use AnnotationsAfter installing tim-annotations, you must add the TIM to your tc-config.xml file. Again, the TIM Update Center can help us with this task: [PROMPT] tim-get.sh info tim-annotations
Terracotta 2.7.0-stable0, as of 20080728-140730 (Revision 9506 by cruise@rh4mo0 from 2.7)
tim-annotations (1.2.0-SNAPSHOT)
Installed: YES
Author : Terracotta, Inc.
Copyright: Copyright (c) 2007 Terracotta, Inc.
Homepage : http://forge.terracotta.org/releases/projects/tim-annotations/
Download : http://download.terracotta.org/maven2/org/terracotta/modules/tim-annotations/1.2.0-SNAPSHOT/tim-annotations-1.2.0-SNAPSHOT.jar
Status :
Annotations package for Terracotta projects
Compatible with TC 2.7.0-SNAPSHOT
Dependencies:
+ modules-common (2.7.0-SNAPSHOT)
Maven Coordinates:
groupId : org.terracotta.modules
artifactId: tim-annotations
version : 1.2.0-SNAPSHOT
Configuration:
<modules>
<module name="tim-annotations" version="1.2.0-SNAPSHOT" />
</modules>
Installed at /Users/tgautier/terracotta-2.7.0-stable0/modules/org/terracotta/modules/tim-annotations/1.2.0-SNAPSHOT
There are no other versions of this TIM that is compatible with TC 2.7.0-SNAPSHOT
The Configuration section lists the appropriate configuration required to configure Terracotta to use this TIM. Add it to the clients section of your tc-config.xml. Using AnnotationsAfter you have installed and configured tim-annotations you are ready to use your annotations.
There are currently 8 total annotations, each corresponds to a configuration element in the tc-config.xml file. They are:
InstrumentedClassUse this annotation to mark a class instrumented. import org.terracotta.modules.annotations.*; @InstrumentedClass public class MyClass { ... } HonorTransientUse this annotation to honor transient fields in the instrumented class. import org.terracotta.modules.annotations.*; @InstrumentedClass @HonorTransient public class MyClass { ... } RootUse this annotation to mark a field as a root. import org.terracotta.modules.annotations.*; public class MyClass { @Root private final Map map = new HashMap(); ... } AutolockUse the AutolockXXX annotations to autolock methods. import org.terracotta.modules.annotations.*; @InstrumentedClass public class MyClass { @AutolockRead public synchronized void getFoo() { return foo; } @AutolockWrite public synchronized void setFoo(int foo) { this.foo = foo; } @AutolockConcurrentWrite public synchronized void setFooConcurrent(int foo) { this.foo = foo; } @AutolockSynchronousWrite public synchronized void setFooSynchronous(int foo) { this.foo = foo; } ... } If you are replacing autolock properties in tc-config.xml with AutolockXXX annotations, you may find that the lock level has not been specified. The default lock level for autolock properties in tc-config-xml is "write". DMIUse the DMI annotation to mark a method for DMI. import org.terracotta.modules.annotations.*; @InstrumentedClass public class MyClass { @DMI public void notify() { … } ... } |
Annotations
(None)