Author: jason.greene(a)jboss.com
Date: 2008-10-21 17:03:54 -0400 (Tue, 21 Oct 2008)
New Revision: 6991
Added:
pojo/tags/2.2.0.GA/
pojo/tags/2.2.0.GA/pom.xml
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java
Removed:
pojo/tags/2.2.0.GA/pom.xml
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java
Log:
Tag 2.2.0.GA
Copied: pojo/tags/2.2.0.GA (from rev 6989, pojo/branches/2.2)
Deleted: pojo/tags/2.2.0.GA/pom.xml
===================================================================
--- pojo/branches/2.2/pom.xml 2008-10-20 21:52:11 UTC (rev 6989)
+++ pojo/tags/2.2.0.GA/pom.xml 2008-10-21 21:03:54 UTC (rev 6991)
@@ -1,299 +0,0 @@
-<?xml version="1.0"?>
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <properties>
- <jbosscache-pojo-version>2.2.0.CR7</jbosscache-pojo-version>
- <jbosscache-core-version>2.2.0.CR7</jbosscache-core-version>
- <jboss.aop.version>2.0.0.CR15</jboss.aop.version>
- </properties>
- <parent>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-common-parent</artifactId>
- <version>1.1</version>
- </parent>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-pojo</artifactId>
- <version>${jbosscache-pojo-version}</version>
- <name>JBoss Cache - POJO Edition</name>
- <description>JBoss Cache - POJO Edition</description>
- <packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>org.jboss.aop</groupId>
- <artifactId>jboss-aop</artifactId>
- <version>${jboss.aop.version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>net.jcip</groupId>
- <artifactId>jcip-annotations</artifactId>
- <version>1.0</version>
- <optional>true</optional>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>javadoc</goal>
- </goals>
- <configuration>
- <aggregate>${jbosscache.reports.aggregate}</aggregate>
- <links>
- <
link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
- <
link>http://java.sun.com/javaee/5/docs/api/</link>
-
<
link>http://labs.jboss.org/file-access/default/members/jbosscache/free...
- </links>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-1</version>
- <executions>
- <execution>
- <id>assemble</id>
- <phase>install</phase>
- <goals>
- <goal>attached</goal>
- </goals>
- <configuration>
- <descriptors>
- <descriptor>assembly/bin.xml</descriptor>
- <descriptor>assembly/doc.xml</descriptor>
- <descriptor>assembly/all.xml</descriptor>
- </descriptors>
-
<finalName>${artifactId}-${jbosscache-pojo-version}</finalName>
- <outputDirectory>target/distribution</outputDirectory>
- <workDirectory>target/assembly/work</workDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <systemProperties>
- <property>
- <name>bind.address</name>
- <value>127.0.0.1</value>
- </property>
- <property>
- <name>java.net.preferIPv4Stack</name>
- <value>true</value>
- </property>
- <property>
- <name>jgroups.stack</name>
- <value>udp</value>
- </property>
- </systemProperties>
- <groups>functional</groups>
- <forkMode>always</forkMode>
-
<argLine>-Djboss.aop.path=${basedir}/src/main/resources/META-INF/pojocache-aop.xml
-javaagent:${settings.localRepository}/org/jboss/aop/jboss-aop/${jboss.aop.version}/jboss-aop-${jboss.aop.version}.jar</argLine>
- <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349)
-->
- <!-- This seems to fail in some cases on 2.3 as well, disable for now
-->
- <useSystemClassLoader>true</useSystemClassLoader>
- <redirectTestOutputToFile>false</redirectTestOutputToFile>
- </configuration>
- </plugin>
- <!-- the docbook generation plugin for the user guide -->
- <plugin>
- <groupId>org.jboss.maven.plugins</groupId>
- <artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.0.0</version>
- <extensions>true</extensions>
- <dependencies>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jbossorg-docbook-xslt</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jbossorg-jdocbook-style</artifactId>
- <version>1.0.0</version>
- <type>jdocbook-style</type>
- </dependency>
- <dependency>
- <groupId>com.uwyn</groupId>
- <artifactId>jhighlight</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>de.java2html</groupId>
- <artifactId>java2html</artifactId>
- <version>5.0</version>
- </dependency>
- <dependency>
- <groupId>org.richfaces.docs</groupId>
- <artifactId>highlight</artifactId>
- <version>3.1.4.GA</version>
- </dependency>
- </dependencies>
- <executions>
-
- <!-- The User Guide-->
- <execution>
- <id>userguide_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
-
<sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
-
<targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
- <finalName>userguide_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- The Tutorial -->
- <execution>
- <id>tutorial_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
-
<sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
-
<targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
- <finalName>tutorial_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- the FAQs -->
- <execution>
- <id>faq_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
-
<sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
-
<targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
- <finalName>faq_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
-
<stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <!-- basic JBoss repository so that the common parent POM in jbosscache-support can
be found -->
- <repositories>
- <repository>
- <id>snapshots.jboss.org</id>
- <
url>http://snapshots.jboss.org/maven2</url>
- </repository>
- <repository>
- <id>repository.jboss.org</id>
- <
url>http://repository.jboss.org/maven2</url>
- </repository>
- </repositories>
-</project>
Copied: pojo/tags/2.2.0.GA/pom.xml (from rev 6990, pojo/branches/2.2/pom.xml)
===================================================================
--- pojo/tags/2.2.0.GA/pom.xml (rev 0)
+++ pojo/tags/2.2.0.GA/pom.xml 2008-10-21 21:03:54 UTC (rev 6991)
@@ -0,0 +1,299 @@
+<?xml version="1.0"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <properties>
+ <jbosscache-pojo-version>2.2.0.GA</jbosscache-pojo-version>
+ <jbosscache-core-version>2.2.0.GA</jbosscache-core-version>
+ <jboss.aop.version>2.0.0.GA</jboss.aop.version>
+ </properties>
+ <parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-common-parent</artifactId>
+ <version>1.1</version>
+ </parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-pojo</artifactId>
+ <version>${jbosscache-pojo-version}</version>
+ <name>JBoss Cache - POJO Edition</name>
+ <description>JBoss Cache - POJO Edition</description>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <version>${jboss.aop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>net.jcip</groupId>
+ <artifactId>jcip-annotations</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>javadoc</goal>
+ </goals>
+ <configuration>
+ <aggregate>${jbosscache.reports.aggregate}</aggregate>
+ <links>
+ <
link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ <
link>http://java.sun.com/javaee/5/docs/api/</link>
+
<
link>http://labs.jboss.org/file-access/default/members/jbosscache/free...
+ </links>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-1</version>
+ <executions>
+ <execution>
+ <id>assemble</id>
+ <phase>install</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly/bin.xml</descriptor>
+ <descriptor>assembly/doc.xml</descriptor>
+ <descriptor>assembly/all.xml</descriptor>
+ </descriptors>
+
<finalName>${artifactId}-${jbosscache-pojo-version}</finalName>
+ <outputDirectory>target/distribution</outputDirectory>
+ <workDirectory>target/assembly/work</workDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>bind.address</name>
+ <value>127.0.0.1</value>
+ </property>
+ <property>
+ <name>java.net.preferIPv4Stack</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>jgroups.stack</name>
+ <value>udp</value>
+ </property>
+ </systemProperties>
+ <groups>functional</groups>
+ <forkMode>always</forkMode>
+
<argLine>-Djboss.aop.path=${basedir}/src/main/resources/META-INF/pojocache-aop.xml
-javaagent:${settings.localRepository}/org/jboss/aop/jboss-aop/${jboss.aop.version}/jboss-aop-${jboss.aop.version}.jar</argLine>
+ <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349)
-->
+ <!-- This seems to fail in some cases on 2.3 as well, disable for now
-->
+ <useSystemClassLoader>true</useSystemClassLoader>
+ <redirectTestOutputToFile>false</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ <!-- the docbook generation plugin for the user guide -->
+ <plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-jdocbook-plugin</artifactId>
+ <version>2.0.0</version>
+ <extensions>true</extensions>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossorg-docbook-xslt</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossorg-jdocbook-style</artifactId>
+ <version>1.0.0</version>
+ <type>jdocbook-style</type>
+ </dependency>
+ <dependency>
+ <groupId>com.uwyn</groupId>
+ <artifactId>jhighlight</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>de.java2html</groupId>
+ <artifactId>java2html</artifactId>
+ <version>5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.docs</groupId>
+ <artifactId>highlight</artifactId>
+ <version>3.1.4.GA</version>
+ </dependency>
+ </dependencies>
+ <executions>
+
+ <!-- The User Guide-->
+ <execution>
+ <id>userguide_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+
<sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+
<targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
+ <finalName>userguide_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+
+ <!-- The Tutorial -->
+ <execution>
+ <id>tutorial_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+
<sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+
<targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
+ <finalName>tutorial_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+
+ <!-- the FAQs -->
+ <execution>
+ <id>faq_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+
<sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+
<targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
+ <finalName>faq_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+
<stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- basic JBoss repository so that the common parent POM in jbosscache-support can
be found -->
+ <repositories>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <
url>http://snapshots.jboss.org/maven2</url>
+ </repository>
+ <repository>
+ <id>repository.jboss.org</id>
+ <
url>http://repository.jboss.org/maven2</url>
+ </repository>
+ </repositories>
+</project>
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,254 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.cache.pojo.impl;
-
-import java.lang.reflect.Field;
-import java.util.*;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.Advised;
-import org.jboss.aop.ClassInstanceAdvisor;
-import org.jboss.aop.InstanceAdvisor;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.Reference;
-import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
-import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
-import org.jboss.cache.pojo.memory.FieldPersistentReference;
-import org.jboss.cache.pojo.util.AopUtil;
-import org.jboss.cache.pojo.util.Instantiator;
-import org.jboss.cache.pojo.util.ObjectUtil;
-
-/**
- * Handling the advised pojo operations. No consideration of object graph here.
- *
- * @author Ben Wang
- * Date: Aug 4, 2005
- * @version $Id$
- */
-class AdvisedPojoHandler extends AbstractHandler
-{
- private final Log log = LogFactory.getLog(AdvisedPojoHandler.class);
- private Cache<Object, Object> cache_;
- private PojoCacheImpl pCache_;
- private PojoUtil util_;
-
- public AdvisedPojoHandler(PojoCacheImpl pCache, InternalHelper internal,
- PojoUtil util)
- {
- pCache_ = pCache;
- cache_ = pCache_.getCache();
- util_ = util;
- }
-
- @Override
- protected Fqn<?> getFqn(Object obj)
- {
- if (obj instanceof Advised)
- {
- InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
- if (advisor == null)
- throw new PojoCacheException("_putObject(): InstanceAdvisor is null for:
" + obj);
-
- // Step Check for cross references
- BaseInterceptor interceptor = AopUtil.findCacheInterceptor(advisor);
- if (interceptor != null)
- return interceptor.getFqn();
- }
-
- return null;
- }
-
- @Override
- protected Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance
pojoInstance) throws CacheException
- {
- CachedType type = pCache_.getCachedType(clazz);
- Object obj = Instantiator.newInstance(clazz);
-
- // Eager initialize final fields, since these may not be intercepted
-
- try
- {
- for (FieldPersistentReference ref : type.getFinalFields())
- {
- Field field = ref.getField();
- Object result;
-
- if (CachedType.isSimpleAttribute(field))
- result = cache_.get(fqn, field.getName());
- else
- result = pCache_.find(fqn, field.getName(), obj);
-
- field.set(obj, result);
- }
- }
- catch (Exception e)
- {
- log.warn("Could not initialize final fields on object: " +
ObjectUtil.identityString(obj));
- }
-
- InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
- CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
- interceptor.setAopInstance(pojoInstance);
- util_.attachInterceptor(obj, advisor, interceptor);
- return obj;
- }
-
- @Override
- protected void put(Fqn<?> fqn, Reference reference, Object obj) throws
CacheException
- {
- CachedType type = pCache_.getCachedType(obj.getClass());
- // We have a clean slate then.
- InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
- // TODO workaround for deserialiased objects
- if (advisor == null)
- {
- advisor = new ClassInstanceAdvisor(obj);
- ((Advised) obj)._setInstanceAdvisor(advisor);
- }
-
- // Let's do batch update via Map instead
- Map map = new HashMap();
- // Always initialize the ref count so we can mark this as an AopNode.
- PojoInstance pojoInstance = InternalHelper.initializeAopInstance(reference);
- map.put(PojoInstance.KEY, pojoInstance);
- pojoInstance.setPojoClass(type.getType());
- // we will do it recursively.
- // Map of sub-objects that are non-primitive
- Map subPojoMap = new HashMap();
-
- for (Iterator i = type.getFields().iterator(); i.hasNext();)
- {
- Field field = (Field) (((FieldPersistentReference) i.next())).get();
- Object value = null;
- try
- {
- value = field.get(obj);
- }
- catch (IllegalAccessException e)
- {
- throw new CacheException("field access failed", e);
- }
-
- // we simply treat field that has @Serializable as a primitive type.
- if (CachedType.isSimpleAttribute(field))
- {
- // switched using batch update
- map.put(field.getName(), value);
- }
- else
- {
- subPojoMap.put(field, value);
- }
- }
-
- // Use option to skip locking since we have parent lock already.
-// cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
-
- cache_.getRoot().addChild(fqn).putAll(map);
-
- // Insert interceptor after PojoInstance has been written to the cache
- // This prevents JBCACHE-1078 with pessimistic locking, optimistic is still a
problem
- CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
- interceptor.setAopInstance(pojoInstance);
- util_.attachInterceptor(obj, advisor, interceptor);
-
-// cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
- // This is in-memory operation only
- InternalHelper.setPojo(pojoInstance, obj);
-
- for (Object o : subPojoMap.keySet())
- {
- Field field = (Field) o;
- Object value = subPojoMap.get(field);
- if (value == null) continue; // really no need to map the POJO.
- pCache_.attach(fqn, value, field.getName(), obj);
- // If it is Collection classes, we replace it with dynamic proxy.
- // But we will have to ignore it if value is null
- if (value instanceof Map || value instanceof List || value instanceof Set)
- {
- Object newValue = pCache_.find(fqn, field.getName(), obj);
- util_.inMemorySubstitution(obj, field, newValue);
- }
- }
-
- // Need to make sure this is behind put such that obj.toString is done correctly.
- if (log.isDebugEnabled())
- {
- log.debug("internalPut(): inserting with fqn: " + fqn);
- }
- }
-
- @Override
- protected Object remove(Fqn<?> fqn, Reference referencingFqn, Object result)
throws CacheException
- {
- CachedType type = pCache_.getCachedType(result.getClass());
- InstanceAdvisor advisor = ((Advised) result)._getInstanceAdvisor();
- for (Iterator i = type.getFields().iterator(); i.hasNext();)
- {
- Field field = (Field) (((FieldPersistentReference) i.next())).get();
- Object value = null;
-
- if (! CachedType.isSimpleAttribute(field))
- {
- value = pCache_.detach(fqn, field.getName(), result);
-
- // Check for Collection. If it is, we need to reset the original reference.
- if ((value instanceof Map || value instanceof List || value instanceof Set))
- {
- // If this Collection class, we are returning the original value already
- util_.inMemorySubstitution(result, field, value);
- }
- }
- else
- {
- // Update last known field state
- value = cache_.get(fqn, field.getName());
- util_.inMemorySubstitution(result, field, value);
- }
- }
-
- cache_.removeNode(fqn);
- // Determine if we want to keep the interceptor for later use.
- CacheFieldInterceptor interceptor = (CacheFieldInterceptor)
AopUtil.findCacheInterceptor(advisor);
- // Remember to remove the interceptor from in-memory object but make sure it
belongs to me first.
- if (interceptor != null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("regularRemoveObject(): removed cache interceptor fqn: "
+ fqn + " interceptor: " + interceptor);
- }
- util_.detachInterceptor(advisor, interceptor);
- }
-
- return result;
- }
-
- @Override
- protected boolean handles(Class<?> clazz)
- {
- return Advised.class.isAssignableFrom(clazz);
- }
-}
Copied: pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java)
===================================================================
--- pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,252 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.cache.pojo.impl;
+
+import java.lang.reflect.Field;
+import java.util.*;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.aop.Advised;
+import org.jboss.aop.ClassInstanceAdvisor;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.Reference;
+import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
+import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
+import org.jboss.cache.pojo.memory.FieldPersistentReference;
+import org.jboss.cache.pojo.util.AopUtil;
+import org.jboss.cache.pojo.util.Instantiator;
+import org.jboss.cache.pojo.util.ObjectUtil;
+
+/**
+ * Handling the advised pojo operations. No consideration of object graph here.
+ *
+ * @author Ben Wang
+ * Date: Aug 4, 2005
+ * @version $Id$
+ */
+class AdvisedPojoHandler extends AbstractHandler
+{
+ private final Log log = LogFactory.getLog(AdvisedPojoHandler.class);
+ private Cache<Object, Object> cache_;
+ private PojoCacheImpl pCache_;
+ private PojoUtil util_;
+
+ public AdvisedPojoHandler(PojoCacheImpl pCache, InternalHelper internal,
+ PojoUtil util)
+ {
+ pCache_ = pCache;
+ cache_ = pCache_.getCache();
+ util_ = util;
+ }
+
+ @Override
+ protected Fqn<?> getFqn(Object obj)
+ {
+ if (obj instanceof Advised)
+ {
+ InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
+ if (advisor == null)
+ throw new PojoCacheException("_putObject(): InstanceAdvisor is null for:
" + obj);
+
+ // Step Check for cross references
+ BaseInterceptor interceptor = AopUtil.findCacheInterceptor(advisor);
+ if (interceptor != null)
+ return interceptor.getFqn();
+ }
+
+ return null;
+ }
+
+ @Override
+ protected Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance
pojoInstance) throws CacheException
+ {
+ CachedType type = pCache_.getCachedType(clazz);
+ Object obj = Instantiator.newInstance(clazz);
+
+ // Eager initialize final fields, since these may not be intercepted
+
+ try
+ {
+ for (FieldPersistentReference ref : type.getFinalFields())
+ {
+ Field field = ref.getField();
+ Object result;
+
+ if (CachedType.isSimpleAttribute(field))
+ result = cache_.get(fqn, field.getName());
+ else
+ result = pCache_.find(fqn, field.getName(), obj);
+
+ field.set(obj, result);
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Could not initialize final fields on object: " +
ObjectUtil.identityString(obj));
+ }
+
+ InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
+ CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
+ interceptor.setAopInstance(pojoInstance);
+ util_.attachInterceptor(obj, advisor, interceptor);
+ return obj;
+ }
+
+ @Override
+ protected void put(Fqn<?> fqn, Reference reference, Object obj) throws
CacheException
+ {
+ CachedType type = pCache_.getCachedType(obj.getClass());
+ // We have a clean slate then.
+ InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
+ // TODO workaround for deserialiased objects
+ if (advisor == null)
+ {
+ advisor = new ClassInstanceAdvisor(obj);
+ ((Advised) obj)._setInstanceAdvisor(advisor);
+ }
+
+ // Let's do batch update via Map instead
+ Map map = new HashMap();
+ // Always initialize the ref count so we can mark this as an AopNode.
+ PojoInstance pojoInstance = InternalHelper.initializeAopInstance(reference);
+ map.put(PojoInstance.KEY, pojoInstance);
+ pojoInstance.setPojoClass(type.getType());
+ // we will do it recursively.
+ // Map of sub-objects that are non-primitive
+ Map subPojoMap = new HashMap();
+
+ for (Iterator i = type.getFields().iterator(); i.hasNext();)
+ {
+ Field field = (Field) (((FieldPersistentReference) i.next())).get();
+ Object value = null;
+ try
+ {
+ value = field.get(obj);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new CacheException("field access failed", e);
+ }
+
+ // we simply treat field that has @Serializable as a primitive type.
+ if (CachedType.isSimpleAttribute(field))
+ {
+ // switched using batch update
+ map.put(field.getName(), value);
+ }
+ else
+ {
+ subPojoMap.put(field, value);
+ }
+ }
+
+ // Use option to skip locking since we have parent lock already.
+// cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
+
+ cache_.getRoot().addChild(fqn).putAll(map);
+
+ // Insert interceptor after PojoInstance has been written to the cache
+ // This prevents JBCACHE-1078 with pessimistic locking, optimistic is still a
problem
+ CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
+ interceptor.setAopInstance(pojoInstance);
+ util_.attachInterceptor(obj, advisor, interceptor);
+
+// cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
+ // This is in-memory operation only
+ InternalHelper.setPojo(pojoInstance, obj);
+
+ for (Object o : subPojoMap.keySet())
+ {
+ Field field = (Field) o;
+ Object value = subPojoMap.get(field);
+ if (value == null) continue; // really no need to map the POJO.
+ pCache_.attach(fqn, value, field.getName(), obj);
+ // If it is Collection classes, we replace it with dynamic proxy.
+ // But we will have to ignore it if value is null
+ if (value instanceof Map || value instanceof List || value instanceof Set)
+ {
+ Object newValue = pCache_.find(fqn, field.getName(), obj);
+ util_.inMemorySubstitution(obj, field, newValue);
+ }
+ }
+
+ // Need to make sure this is behind put such that obj.toString is done correctly.
+ if (log.isTraceEnabled())
+ log.trace("internalPut(): inserting with fqn: " + fqn);
+ }
+
+ @Override
+ protected Object remove(Fqn<?> fqn, Reference referencingFqn, Object result)
throws CacheException
+ {
+ CachedType type = pCache_.getCachedType(result.getClass());
+ InstanceAdvisor advisor = ((Advised) result)._getInstanceAdvisor();
+ for (Iterator i = type.getFields().iterator(); i.hasNext();)
+ {
+ Field field = (Field) (((FieldPersistentReference) i.next())).get();
+ Object value = null;
+
+ if (! CachedType.isSimpleAttribute(field))
+ {
+ value = pCache_.detach(fqn, field.getName(), result);
+
+ // Check for Collection. If it is, we need to reset the original reference.
+ if ((value instanceof Map || value instanceof List || value instanceof Set))
+ {
+ // If this Collection class, we are returning the original value already
+ util_.inMemorySubstitution(result, field, value);
+ }
+ }
+ else
+ {
+ // Update last known field state
+ value = cache_.get(fqn, field.getName());
+ util_.inMemorySubstitution(result, field, value);
+ }
+ }
+
+ cache_.removeNode(fqn);
+ // Determine if we want to keep the interceptor for later use.
+ CacheFieldInterceptor interceptor = (CacheFieldInterceptor)
AopUtil.findCacheInterceptor(advisor);
+ // Remember to remove the interceptor from in-memory object but make sure it
belongs to me first.
+ if (interceptor != null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("regularRemoveObject(): removed cache interceptor fqn: "
+ fqn + " interceptor: " + interceptor);
+ }
+ util_.detachInterceptor(advisor, interceptor);
+ }
+
+ return result;
+ }
+
+ @Override
+ protected boolean handles(Class<?> clazz)
+ {
+ return Advised.class.isAssignableFrom(clazz);
+ }
+}
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,290 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.impl;
-
-import java.util.*;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.proxy.ClassProxy;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.Reference;
-import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
-import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
-import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
-
-/**
- * Handling the Collection class management. Has no consideration of object graph here.
- *
- * @author Ben Wang
- * Date: Aug 4, 2005
- * @version $Id$
- */
-class CollectionClassHandler extends AbstractHandler
-{
- private final Log log = LogFactory.getLog(CollectionClassHandler.class);
- private Cache<Object, Object> cache_;
- private PojoCacheImpl pCache_;
- private InternalHelper internal_;
-
- public CollectionClassHandler(PojoCacheImpl pCache, InternalHelper internal)
- {
- pCache_ = pCache;
- cache_ = pCache_.getCache();
- internal_ = internal;
- }
-
- protected Fqn<?> getFqn(Object collection)
- {
- if (! (collection instanceof ClassProxy))
- return null;
-
- BaseInterceptor interceptor = CollectionInterceptorUtil.getInterceptor((ClassProxy)
collection);
- return interceptor != null ? interceptor.getFqn() : null;
- }
-
- protected Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance)
- throws CacheException
- {
- Object obj = null;
- try
- {
- if (Map.class.isAssignableFrom(clazz))
- {
- Object map = clazz.newInstance();
- obj = CollectionInterceptorUtil.createMapProxy(pCache_, fqn, clazz, (Map)
map);
- }
- else if (List.class.isAssignableFrom(clazz))
- {
- Object list = clazz.newInstance();
- obj = CollectionInterceptorUtil.createListProxy(pCache_, fqn, clazz, (List)
list);
- }
- else if (Set.class.isAssignableFrom(clazz))
- {
- Object set = clazz.newInstance();
- obj = CollectionInterceptorUtil.createSetProxy(pCache_, fqn, clazz, (Set)
set);
- }
- }
- catch (Exception e)
- {
- throw new CacheException("failure creating proxy", e);
- }
-
- return obj;
- }
-
- protected void put(Fqn fqn, Reference reference, Object obj) throws CacheException
- {
- boolean isCollection = false;
-
- CachedType type = null;
- if (obj instanceof ClassProxy)
- {
- throw new IllegalStateException("CollectionClassHandler.put(): obj is an
ClassProxy instance " + obj);
- }
-
- type = pCache_.getCachedType(obj.getClass());
-
- //JBCACHE-760: for collection - put initialized aopInstance in fqn
- if (!(obj instanceof Map || obj instanceof List || obj instanceof Set))
- {
- return;
- }
-
- // Always initialize the ref count so that we can mark this as an AopNode.
- PojoInstance pojoInstance = InternalHelper.initializeAopInstance(reference);
- pojoInstance.set(obj);
- pojoInstance.setPojoClass(type.getType());
- cache_.put(fqn, PojoInstance.KEY, pojoInstance);
-
- if (obj instanceof Map)
- {
- if (log.isDebugEnabled())
- {
- log.debug("collectionPutObject(): aspectized obj is a Map type of size:
" + ((Map) obj).size());
- }
-
- // Let's replace it with a proxy if necessary
- Map map = (Map) obj;
- if (!(obj instanceof ClassProxy))
- {
- Class clazz = obj.getClass();
- try
- {
- obj = CollectionInterceptorUtil.createMapProxy(pCache_, fqn, clazz, (Map)
obj);
- }
- catch (Exception e)
- {
- throw new CacheException("failure creating proxy", e);
- }
-
- checkMapRecursion(map, obj);
- }
-
- isCollection = true;
- // populate via the proxied collection
- for (Iterator i = map.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry) i.next();
- ((Map) obj).put(entry.getKey(), entry.getValue());
- }
-
- }
- else if (obj instanceof List)
- {
- if (log.isDebugEnabled())
- {
- log.debug("collectionPutObject(): aspectized obj is a List type of size:
"
- + ((List) obj).size());
- }
-
- List list = (List) obj;
-
- // Let's replace it with a proxy if necessary
- if (!(obj instanceof ClassProxy))
- {
- Class clazz = obj.getClass();
- try
- {
- obj = CollectionInterceptorUtil.createListProxy(pCache_, fqn, clazz,
(List) obj);
- }
- catch (Exception e)
- {
- throw new CacheException("failure creating proxy", e);
- }
-
- checkListRecursion(list, obj);
- }
-
- isCollection = true;
- // populate via the proxied collection
- for (Iterator i = list.iterator(); i.hasNext();)
- {
- ((List) obj).add(i.next());
- }
-
- }
- else if (obj instanceof Set)
- {
- if (log.isDebugEnabled())
- {
- log.debug("collectionPutObject(): aspectized obj is a Set type of size:
"
- + ((Set) obj).size());
- }
-
- Set set = (Set) obj;
-
- // Let's replace it with a proxy if necessary
- if (!(obj instanceof ClassProxy))
- {
- Class clazz = obj.getClass();
- try
- {
- obj = CollectionInterceptorUtil.createSetProxy(pCache_, fqn, clazz, (Set)
obj);
- }
- catch (Exception e)
- {
- throw new CacheException("failure creating proxy", e);
- }
-
- checkSetRecursion(set, obj);
- }
-
- isCollection = true;
- // populate via the proxied collection
- for (Iterator i = set.iterator(); i.hasNext();)
- {
- ((Set) obj).add(i.next());
- }
-
- }
-
- if (isCollection)
- {
- // Need to reset it here in case this is a new proxy instance
- pojoInstance.set(obj);
- // Attach pojoReference to that interceptor
- BaseInterceptor baseInterceptor = (BaseInterceptor)
CollectionInterceptorUtil.getInterceptor(
- (ClassProxy) obj);
- baseInterceptor.setAopInstance(pojoInstance);
- }
- }
-
- private void checkListRecursion(List list, Object obj)
- {
- while (true)
- {
- int i = list.indexOf(list); // check for recursion
- if (i == -1) break;
-
- list.remove(list);
- list.add(i, obj);
- }
- }
-
- private void checkSetRecursion(Set set, Object obj)
- {
- if (set.remove(set))
- {
- set.add(obj); // replace with proxy
- throw new PojoCacheException("CollectionClassHandler.checkSetRecursion():
" +
- "detect a recursive set (e.g., set inside the
same set). This will fail to " +
- "replicate even outside of PojoCache with
HashSet. " + set);
- }
- }
-
- private void checkMapRecursion(Map map, Object obj)
- {
- Map m = java.util.Collections.unmodifiableMap(map);
-
- for (Object k : m.keySet())
- {
- if (m == k)
- {
- throw new
PojoCacheException("CollectionClassHandler.checkMapRecursion(): " +
- " Can't handle the recursion map where
it is nested in a constant key " + map);
- }
-
- Object v = m.get(k);
- if (v == map)
- {
- throw new
PojoCacheException("CollectionClassHandler.checkMapRecursion(): " +
- "detect a recursive map (e.g., map inside
the same map). This will fail to " +
- "replicate even outside of PojoCache with
HashMap because of hashCode. " + map);
- // recursion here, replace it with proxy
-// map.put(k, obj);
- }
- }
- }
-
- @Override
- protected Object remove(Fqn<?> fqn, Reference referencingFqn, Object obj) throws
CacheException
- {
- if (!(obj instanceof ClassProxy))
- {
- throw new
PojoCacheException("CollectionClassHandler.collectionRemoveObject(): object is not a
proxy :" + obj);
- }
-
- AbstractCollectionInterceptor interceptor = (AbstractCollectionInterceptor)
CollectionInterceptorUtil.getInterceptor((ClassProxy) obj);
- // detach the interceptor. This will trigger a copy and remove.
- (new PojoUtil()).detachCollectionInterceptor(interceptor);
- cache_.removeNode(fqn);
-
- return interceptor.getCurrentCopy();
- }
-
-
- @Override
- protected boolean handles(Class<?> clazz)
- {
- return Collection.class.isAssignableFrom(clazz) ||
Map.class.isAssignableFrom(clazz);
- }
-}
Copied:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java)
===================================================================
---
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/CollectionClassHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,290 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.impl;
+
+import java.util.*;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.aop.proxy.ClassProxy;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.Reference;
+import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
+import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
+import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
+
+/**
+ * Handling the Collection class management. Has no consideration of object graph here.
+ *
+ * @author Ben Wang
+ * Date: Aug 4, 2005
+ * @version $Id$
+ */
+class CollectionClassHandler extends AbstractHandler
+{
+ private final Log log = LogFactory.getLog(CollectionClassHandler.class);
+ private Cache<Object, Object> cache_;
+ private PojoCacheImpl pCache_;
+ private InternalHelper internal_;
+
+ public CollectionClassHandler(PojoCacheImpl pCache, InternalHelper internal)
+ {
+ pCache_ = pCache;
+ cache_ = pCache_.getCache();
+ internal_ = internal;
+ }
+
+ protected Fqn<?> getFqn(Object collection)
+ {
+ if (! (collection instanceof ClassProxy))
+ return null;
+
+ BaseInterceptor interceptor = CollectionInterceptorUtil.getInterceptor((ClassProxy)
collection);
+ return interceptor != null ? interceptor.getFqn() : null;
+ }
+
+ protected Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance)
+ throws CacheException
+ {
+ Object obj = null;
+ try
+ {
+ if (Map.class.isAssignableFrom(clazz))
+ {
+ Object map = clazz.newInstance();
+ obj = CollectionInterceptorUtil.createMapProxy(pCache_, fqn, clazz, (Map)
map);
+ }
+ else if (List.class.isAssignableFrom(clazz))
+ {
+ Object list = clazz.newInstance();
+ obj = CollectionInterceptorUtil.createListProxy(pCache_, fqn, clazz, (List)
list);
+ }
+ else if (Set.class.isAssignableFrom(clazz))
+ {
+ Object set = clazz.newInstance();
+ obj = CollectionInterceptorUtil.createSetProxy(pCache_, fqn, clazz, (Set)
set);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("failure creating proxy", e);
+ }
+
+ return obj;
+ }
+
+ protected void put(Fqn fqn, Reference reference, Object obj) throws CacheException
+ {
+ boolean isCollection = false;
+
+ CachedType type = null;
+ if (obj instanceof ClassProxy)
+ {
+ throw new IllegalStateException("CollectionClassHandler.put(): obj is an
ClassProxy instance " + obj);
+ }
+
+ type = pCache_.getCachedType(obj.getClass());
+
+ //JBCACHE-760: for collection - put initialized aopInstance in fqn
+ if (!(obj instanceof Map || obj instanceof List || obj instanceof Set))
+ {
+ return;
+ }
+
+ // Always initialize the ref count so that we can mark this as an AopNode.
+ PojoInstance pojoInstance = InternalHelper.initializeAopInstance(reference);
+ pojoInstance.set(obj);
+ pojoInstance.setPojoClass(type.getType());
+ cache_.put(fqn, PojoInstance.KEY, pojoInstance);
+
+ if (obj instanceof Map)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("collectionPutObject(): aspectized obj is a Map type of size:
" + ((Map) obj).size());
+ }
+
+ // Let's replace it with a proxy if necessary
+ Map map = (Map) obj;
+ if (!(obj instanceof ClassProxy))
+ {
+ Class clazz = obj.getClass();
+ try
+ {
+ obj = CollectionInterceptorUtil.createMapProxy(pCache_, fqn, clazz, (Map)
obj);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("failure creating proxy", e);
+ }
+
+ checkMapRecursion(map, obj);
+ }
+
+ isCollection = true;
+ // populate via the proxied collection
+ for (Iterator i = map.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry) i.next();
+ ((Map) obj).put(entry.getKey(), entry.getValue());
+ }
+
+ }
+ else if (obj instanceof List)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("collectionPutObject(): aspectized obj is a List type of size:
"
+ + ((List) obj).size());
+ }
+
+ List list = (List) obj;
+
+ // Let's replace it with a proxy if necessary
+ if (!(obj instanceof ClassProxy))
+ {
+ Class clazz = obj.getClass();
+ try
+ {
+ obj = CollectionInterceptorUtil.createListProxy(pCache_, fqn, clazz,
(List) obj);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("failure creating proxy", e);
+ }
+
+ checkListRecursion(list, obj);
+ }
+
+ isCollection = true;
+ // populate via the proxied collection
+ for (Iterator i = list.iterator(); i.hasNext();)
+ {
+ ((List) obj).add(i.next());
+ }
+
+ }
+ else if (obj instanceof Set)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("collectionPutObject(): aspectized obj is a Set type of size:
"
+ + ((Set) obj).size());
+ }
+
+ Set set = (Set) obj;
+
+ // Let's replace it with a proxy if necessary
+ if (!(obj instanceof ClassProxy))
+ {
+ Class clazz = obj.getClass();
+ try
+ {
+ obj = CollectionInterceptorUtil.createSetProxy(pCache_, fqn, clazz, (Set)
obj);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("failure creating proxy", e);
+ }
+
+ checkSetRecursion(set, obj);
+ }
+
+ isCollection = true;
+ // populate via the proxied collection
+ for (Iterator i = set.iterator(); i.hasNext();)
+ {
+ ((Set) obj).add(i.next());
+ }
+
+ }
+
+ if (isCollection)
+ {
+ // Need to reset it here in case this is a new proxy instance
+ pojoInstance.set(obj);
+ // Attach pojoReference to that interceptor
+ BaseInterceptor baseInterceptor = (BaseInterceptor)
CollectionInterceptorUtil.getInterceptor(
+ (ClassProxy) obj);
+ baseInterceptor.setAopInstance(pojoInstance);
+ }
+ }
+
+ private void checkListRecursion(List list, Object obj)
+ {
+ while (true)
+ {
+ int i = list.indexOf(list); // check for recursion
+ if (i == -1) break;
+
+ list.remove(list);
+ list.add(i, obj);
+ }
+ }
+
+ private void checkSetRecursion(Set set, Object obj)
+ {
+ if (set.remove(set))
+ {
+ set.add(obj); // replace with proxy
+ throw new PojoCacheException("CollectionClassHandler.checkSetRecursion():
" +
+ "detect a recursive set (e.g., set inside the
same set). This will fail to " +
+ "replicate even outside of PojoCache with
HashSet. " + set);
+ }
+ }
+
+ private void checkMapRecursion(Map map, Object obj)
+ {
+ Map m = java.util.Collections.unmodifiableMap(map);
+
+ for (Object k : m.keySet())
+ {
+ if (m == k)
+ {
+ throw new
PojoCacheException("CollectionClassHandler.checkMapRecursion(): " +
+ " Can't handle the recursion map where
it is nested in a constant key " + map);
+ }
+
+ Object v = m.get(k);
+ if (v == map)
+ {
+ throw new
PojoCacheException("CollectionClassHandler.checkMapRecursion(): " +
+ "detect a recursive map (e.g., map inside
the same map). This will fail to " +
+ "replicate even outside of PojoCache with
HashMap because of hashCode. " + map);
+ // recursion here, replace it with proxy
+// map.put(k, obj);
+ }
+ }
+ }
+
+ @Override
+ protected Object remove(Fqn<?> fqn, Reference referencingFqn, Object obj) throws
CacheException
+ {
+ if (!(obj instanceof ClassProxy))
+ {
+ throw new
PojoCacheException("CollectionClassHandler.collectionRemoveObject(): object is not a
proxy :" + obj);
+ }
+
+ AbstractCollectionInterceptor interceptor = (AbstractCollectionInterceptor)
CollectionInterceptorUtil.getInterceptor((ClassProxy) obj);
+ // detach the interceptor. This will trigger a copy and remove.
+ (new PojoUtil()).detachCollectionInterceptor(interceptor);
+ cache_.removeNode(fqn);
+
+ return interceptor.getCurrentCopy();
+ }
+
+
+ @Override
+ protected boolean handles(Class<?> clazz)
+ {
+ return Collection.class.isAssignableFrom(clazz) ||
Map.class.isAssignableFrom(clazz);
+ }
+}
Deleted: pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,365 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.cache.pojo.impl;
-
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.*;
-import org.jboss.cache.lock.UpgradeException;
-import org.jboss.cache.pojo.*;
-import org.jboss.cache.pojo.util.ObjectUtil;
-
-/**
- * Internal helper class to handle internal cache sotre, that is, the portion that is not
part of
- * user's data.
- *
- * @author Ben Wang
- */
-public class InternalHelper
-{
- private static Log log = LogFactory.getLog(InternalHelper.class.getName());
-
- private Cache<Object, Object> cache;
- private PojoCache pcache;
-
- InternalHelper(PojoCache pcache)
- {
- this.cache = pcache.getCache();
- this.pcache = pcache;
- }
-
- PojoInstance getPojoInstance(Fqn fqn) throws CacheException
- {
- return (PojoInstance) get(fqn, PojoInstance.KEY, true);
- }
-
- PojoReference getPojoReference(Fqn fqn, String field) throws CacheException
- {
- if (field == null)
- field = PojoReference.KEY;
-
- return (PojoReference) get(fqn, field, true);
- }
-
- PojoReference getPojoReference(Fqn fqn) throws CacheException
- {
- return getPojoReference(fqn, null);
- }
-
-
- static PojoInstance initializeAopInstance(Reference reference)
- {
- PojoInstance pojoInstance = new PojoInstance();
-
- pojoInstance.incrementRefCount(reference);
- return pojoInstance;
- }
-
- /**
- * Increment reference count for the pojo. Note that this is not thread safe or
atomic.
- * @param reference TODO
- */
- int incrementRefCount(Fqn originalFqn, Reference reference) throws CacheException
- {
- PojoInstance pojoInstance = getPojoInstance(originalFqn);
- if (pojoInstance == null)
- throw new PojoCacheException("InternalDelegate.incrementRefCount(): null
pojoReference for fqn: " + originalFqn);
-
- int count = pojoInstance.incrementRefCount(reference);
- // need to update it.
- put(originalFqn, PojoInstance.KEY, pojoInstance);
- return count;
- }
-
- /**
- * Has a delegate method so we can use the switch.
- */
-
- Object get(Fqn fqn, Object key) throws CacheException
- {
- return get(fqn, key, false);
- }
-
- private Object get(Fqn fqn, Object key, boolean gravitate) throws CacheException
- {
- // Only gravitate when we have to and only when the user has enabled it
- if (gravitate && pcache.getThreadContext().isGravitationEnabled())
- {
-
cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
- Object obj = cache.get(fqn, key);
-
cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(false);
- return obj;
- }
-
- return cache.get(fqn, key);
- }
-
- private void put(Fqn fqn, Object key, Object value) throws CacheException
- {
- cache.put(fqn, key, value);
- }
-
- void put(Fqn fqn, Map map) throws CacheException
- {
- cache.put(fqn, map);
- }
-
-
- /**
- * decrement reference count for the pojo. Note that this is not thread safe or
atomic.
- */
- int decrementRefCount(Fqn originalFqn, Reference reference) throws CacheException
- {
- PojoInstance pojoInstance = getPojoInstance(originalFqn);
- if (pojoInstance == null)
- throw new PojoCacheException("InternalDelegate.decrementRefCount(): null
pojoReference.");
-
- int count = pojoInstance.decrementRefCount(reference);
-
- if (count < -1) // can't dip below -1
- throw new PojoCacheException("InternalDelegate.decrementRefCount(): null
pojoReference.");
-
- // need to update it.
- put(originalFqn, PojoInstance.KEY, pojoInstance);
- return count;
- }
-
- static boolean isReferenced(PojoInstance pojoInstance)
- {
- // If ref counter is greater than 0, we fqn is being referenced.
- return (pojoInstance.getRefCount() > 0);
- }
-
- Object getPojo(Fqn fqn, String field) throws CacheException
- {
- PojoReference pojoReference = getPojoReference(fqn, field);
- Fqn realFqn = null;
- if (pojoReference != null)
- {
- // This is outward facing node
- realFqn = pojoReference.getFqn();
- }
- else
- {
- // If we are looking for a field then there must be a reference
- if (field != null)
- return null;
-
- // This is the internal node.
- realFqn = fqn;
- }
-
- PojoInstance pojoInstance = getPojoInstance(realFqn);
- if (pojoInstance == null)
- return null;
-
- return pojoInstance.get();
- }
-
- void setPojo(Fqn fqn, Object pojo) throws CacheException
- {
- PojoInstance pojoInstance = getPojoInstance(fqn);
- if (pojoInstance == null)
- {
- pojoInstance = new PojoInstance();
- put(fqn, PojoInstance.KEY, pojoInstance);
- }
-
- pojoInstance.set(pojo);
- // No need to do a cache put since pojo is transient anyway.
- }
-
- static boolean isMultipleReferenced(PojoInstance pojoInstance)
- {
- if (pojoInstance.getRefCount() > (PojoInstance.INITIAL_COUNTER_VALUE + 1))
return true;
-
- return false;
- }
-
- static void setPojo(PojoInstance pojoInstance, Object pojo)
- {
- // No need to do a cache put since pojo is transient anyway.
- pojoInstance.set(pojo);
- }
-
- void setPojo(Fqn fqn, Object pojo, PojoInstance pojoInstance) throws CacheException
- {
- if (pojoInstance == null)
- {
- pojoInstance = new PojoInstance();
- put(fqn, PojoInstance.KEY, pojoInstance);
- }
-
- pojoInstance.set(pojo);
- // No need to do a cache put since pojo is transient anyway.
- }
-
- void putPojoReference(Fqn fqn, PojoReference pojoReference) throws CacheException
- {
- putPojoReference(fqn, pojoReference, PojoReference.KEY);
- }
-
- void putPojoReference(Fqn fqn, PojoReference pojoReference, String field) throws
CacheException
- {
- if (field == null)
- field = PojoReference.KEY;
-
- put(fqn, field, pojoReference);
- }
-
- void putAopClazz(Fqn fqn, Class clazz) throws CacheException
- {
- put(fqn, InternalConstant.CLASS_INTERNAL, clazz);
- }
-
- /**
- * We store the class name in string and put it in map instead of directly putting
- * it into cache for optimization.
- */
- static void putAopClazz(Class clazz, Map map)
- {
- map.put(InternalConstant.CLASS_INTERNAL, clazz);
- }
-
- Class peekAopClazz(Fqn fqn) throws CacheException
- {
- return (Class) get(fqn, InternalConstant.CLASS_INTERNAL);
- }
-
- void removeInternalAttributes(Fqn fqn) throws CacheException
- {
- cache.remove(fqn, PojoInstance.KEY);
- cache.remove(fqn, InternalConstant.CLASS_INTERNAL);
- }
-
- void cleanUp(Fqn fqn, String field) throws CacheException
- {
- if (field != null)
- {
- cache.remove(fqn, field);
- return;
- }
-
- // We can't do a brute force remove anymore?
- if (cache.getRoot().getChild(fqn).getChildren().size() == 0)
- {
- // remove everything
- cache.removeNode(fqn);
-// cache_.getRoot().getChild(fqn).clearData();
-// removeNodeWithoutInterceptor(fqn);
- }
- else
- {
- // Assume everything here is all PojoCache data for optimization
- cache.getRoot().getChild(fqn).clearData();
- if (log.isTraceEnabled())
- {
- log.trace("cleanup(): fqn: " + fqn + " is not empty. That
means it has sub-pojos. Will not remove node");
- }
- }
- }
-
- String createIndirectFqn(String fqn) throws CacheException
- {
- String indirectFqn = getIndirectFqn(fqn);
- Fqn internalFqn = getInternalFqn(fqn);
- put(internalFqn, indirectFqn, fqn);
- return indirectFqn;
- }
-
- private Fqn getInternalFqn(String fqn)
- {
- if (fqn == null || fqn.length() == 0)
- throw new IllegalStateException("InternalDelegate.getInternalFqn(). fqn is
either null or empty!");
-
- String indirectFqn = getIndirectFqn(fqn);
- return new Fqn(InternalConstant.JBOSS_INTERNAL_MAP, indirectFqn);
-// return JBOSS_INTERNAL_MAP;
- }
-
- static String getIndirectFqn(String fqn)
- {
- // TODO This is not unique. Will need to come up with a better one in the future.
- return ObjectUtil.getIndirectFqn(fqn);
- }
-
- void removeIndirectFqn(String oldFqn) throws CacheException
- {
- String indirectFqn = getIndirectFqn(oldFqn);
- cache.remove(getInternalFqn(oldFqn), indirectFqn);
- }
-
- void setIndirectFqn(String oldFqn, String newFqn) throws CacheException
- {
- String indirectFqn = getIndirectFqn(oldFqn);
- Fqn tmpFqn = getInternalFqn(oldFqn);
- put(tmpFqn, indirectFqn, newFqn);
- }
-
- void updateIndirectFqn(Fqn originalFqn, Fqn newFqn) throws CacheException
- {
- put(getInternalFqn(originalFqn.toString()), getIndirectFqn(originalFqn.toString()),
newFqn.toString());
- }
-
- private String getRefFqnFromAlias(String aliasFqn) throws CacheException
- {
- return (String) get(getInternalFqn(aliasFqn), aliasFqn, true);
- }
-
- /**
- * Test if this internal node.
- *
- * @param fqn
- */
- public static boolean isInternalNode(Fqn fqn)
- {
- // we ignore all the node events corresponding to JBOSS_INTERNAL
- if (fqn.isChildOrEquals(InternalConstant.JBOSS_INTERNAL)) return true;
-
- return false;
- }
-
- public boolean lockPojo(Fqn id) throws CacheException
- {
- final int RETRY = 5;
-
- if (log.isDebugEnabled())
- log.debug("lockPojo(): id:" + id);
-
- boolean isNeeded = true;
- int retry = 0;
-
- while (isNeeded)
- {
- try
- {
- cache.put(id, InternalConstant.POJOCACHE_LOCK, "LOCK");
- isNeeded = false;
- }
- catch (UpgradeException upe)
- {
- log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will
re-try. id: " + id
- + " retry times: " + retry);
- if (retry++ > RETRY)
- return false;
-
- // try to sleep a little as well.
- try
- {
- Thread.sleep(10);
- }
- catch (InterruptedException e)
- {
- }
- }
- }
-
- return true;
- }
-}
\ No newline at end of file
Copied: pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java)
===================================================================
--- pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,365 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.pojo.impl;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.*;
+import org.jboss.cache.lock.UpgradeException;
+import org.jboss.cache.pojo.*;
+import org.jboss.cache.pojo.util.ObjectUtil;
+
+/**
+ * Internal helper class to handle internal cache sotre, that is, the portion that is not
part of
+ * user's data.
+ *
+ * @author Ben Wang
+ */
+public class InternalHelper
+{
+ private static Log log = LogFactory.getLog(InternalHelper.class.getName());
+
+ private Cache<Object, Object> cache;
+ private PojoCache pcache;
+
+ InternalHelper(PojoCache pcache)
+ {
+ this.cache = pcache.getCache();
+ this.pcache = pcache;
+ }
+
+ PojoInstance getPojoInstance(Fqn fqn) throws CacheException
+ {
+ return (PojoInstance) get(fqn, PojoInstance.KEY, true);
+ }
+
+ PojoReference getPojoReference(Fqn fqn, String field) throws CacheException
+ {
+ if (field == null)
+ field = PojoReference.KEY;
+
+ return (PojoReference) get(fqn, field, true);
+ }
+
+ PojoReference getPojoReference(Fqn fqn) throws CacheException
+ {
+ return getPojoReference(fqn, null);
+ }
+
+
+ static PojoInstance initializeAopInstance(Reference reference)
+ {
+ PojoInstance pojoInstance = new PojoInstance();
+
+ pojoInstance.incrementRefCount(reference);
+ return pojoInstance;
+ }
+
+ /**
+ * Increment reference count for the pojo. Note that this is not thread safe or
atomic.
+ * @param reference TODO
+ */
+ int incrementRefCount(Fqn originalFqn, Reference reference) throws CacheException
+ {
+ PojoInstance pojoInstance = getPojoInstance(originalFqn);
+ if (pojoInstance == null)
+ throw new PojoCacheException("InternalDelegate.incrementRefCount(): null
pojoReference for fqn: " + originalFqn);
+
+ int count = pojoInstance.incrementRefCount(reference);
+ // need to update it.
+ put(originalFqn, PojoInstance.KEY, pojoInstance);
+ return count;
+ }
+
+ /**
+ * Has a delegate method so we can use the switch.
+ */
+
+ Object get(Fqn fqn, Object key) throws CacheException
+ {
+ return get(fqn, key, false);
+ }
+
+ private Object get(Fqn fqn, Object key, boolean gravitate) throws CacheException
+ {
+ // Only gravitate when we have to and only when the user has enabled it
+ if (gravitate && pcache.getThreadContext().isGravitationEnabled())
+ {
+
cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+ Object obj = cache.get(fqn, key);
+
cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(false);
+ return obj;
+ }
+
+ return cache.get(fqn, key);
+ }
+
+ private void put(Fqn fqn, Object key, Object value) throws CacheException
+ {
+ cache.put(fqn, key, value);
+ }
+
+ void put(Fqn fqn, Map map) throws CacheException
+ {
+ cache.put(fqn, map);
+ }
+
+
+ /**
+ * decrement reference count for the pojo. Note that this is not thread safe or
atomic.
+ */
+ int decrementRefCount(Fqn originalFqn, Reference reference) throws CacheException
+ {
+ PojoInstance pojoInstance = getPojoInstance(originalFqn);
+ if (pojoInstance == null)
+ throw new PojoCacheException("InternalDelegate.decrementRefCount(): null
pojoReference.");
+
+ int count = pojoInstance.decrementRefCount(reference);
+
+ if (count < -1) // can't dip below -1
+ throw new PojoCacheException("InternalDelegate.decrementRefCount(): null
pojoReference.");
+
+ // need to update it.
+ put(originalFqn, PojoInstance.KEY, pojoInstance);
+ return count;
+ }
+
+ static boolean isReferenced(PojoInstance pojoInstance)
+ {
+ // If ref counter is greater than 0, we fqn is being referenced.
+ return (pojoInstance.getRefCount() > 0);
+ }
+
+ Object getPojo(Fqn fqn, String field) throws CacheException
+ {
+ PojoReference pojoReference = getPojoReference(fqn, field);
+ Fqn realFqn = null;
+ if (pojoReference != null)
+ {
+ // This is outward facing node
+ realFqn = pojoReference.getFqn();
+ }
+ else
+ {
+ // If we are looking for a field then there must be a reference
+ if (field != null)
+ return null;
+
+ // This is the internal node.
+ realFqn = fqn;
+ }
+
+ PojoInstance pojoInstance = getPojoInstance(realFqn);
+ if (pojoInstance == null)
+ return null;
+
+ return pojoInstance.get();
+ }
+
+ void setPojo(Fqn fqn, Object pojo) throws CacheException
+ {
+ PojoInstance pojoInstance = getPojoInstance(fqn);
+ if (pojoInstance == null)
+ {
+ pojoInstance = new PojoInstance();
+ put(fqn, PojoInstance.KEY, pojoInstance);
+ }
+
+ pojoInstance.set(pojo);
+ // No need to do a cache put since pojo is transient anyway.
+ }
+
+ static boolean isMultipleReferenced(PojoInstance pojoInstance)
+ {
+ if (pojoInstance.getRefCount() > (PojoInstance.INITIAL_COUNTER_VALUE + 1))
return true;
+
+ return false;
+ }
+
+ static void setPojo(PojoInstance pojoInstance, Object pojo)
+ {
+ // No need to do a cache put since pojo is transient anyway.
+ pojoInstance.set(pojo);
+ }
+
+ void setPojo(Fqn fqn, Object pojo, PojoInstance pojoInstance) throws CacheException
+ {
+ if (pojoInstance == null)
+ {
+ pojoInstance = new PojoInstance();
+ put(fqn, PojoInstance.KEY, pojoInstance);
+ }
+
+ pojoInstance.set(pojo);
+ // No need to do a cache put since pojo is transient anyway.
+ }
+
+ void putPojoReference(Fqn fqn, PojoReference pojoReference) throws CacheException
+ {
+ putPojoReference(fqn, pojoReference, PojoReference.KEY);
+ }
+
+ void putPojoReference(Fqn fqn, PojoReference pojoReference, String field) throws
CacheException
+ {
+ if (field == null)
+ field = PojoReference.KEY;
+
+ put(fqn, field, pojoReference);
+ }
+
+ void putAopClazz(Fqn fqn, Class clazz) throws CacheException
+ {
+ put(fqn, InternalConstant.CLASS_INTERNAL, clazz);
+ }
+
+ /**
+ * We store the class name in string and put it in map instead of directly putting
+ * it into cache for optimization.
+ */
+ static void putAopClazz(Class clazz, Map map)
+ {
+ map.put(InternalConstant.CLASS_INTERNAL, clazz);
+ }
+
+ Class peekAopClazz(Fqn fqn) throws CacheException
+ {
+ return (Class) get(fqn, InternalConstant.CLASS_INTERNAL);
+ }
+
+ void removeInternalAttributes(Fqn fqn) throws CacheException
+ {
+ cache.remove(fqn, PojoInstance.KEY);
+ cache.remove(fqn, InternalConstant.CLASS_INTERNAL);
+ }
+
+ void cleanUp(Fqn fqn, String field) throws CacheException
+ {
+ if (field != null)
+ {
+ cache.remove(fqn, field);
+ return;
+ }
+
+ // We can't do a brute force remove anymore?
+ if (cache.getRoot().getChild(fqn).getChildren().size() == 0)
+ {
+ // remove everything
+ cache.removeNode(fqn);
+// cache_.getRoot().getChild(fqn).clearData();
+// removeNodeWithoutInterceptor(fqn);
+ }
+ else
+ {
+ // Assume everything here is all PojoCache data for optimization
+ cache.getRoot().getChild(fqn).clearData();
+ if (log.isTraceEnabled())
+ {
+ log.trace("cleanup(): fqn: " + fqn + " is not empty. That
means it has sub-pojos. Will not remove node");
+ }
+ }
+ }
+
+ String createIndirectFqn(String fqn) throws CacheException
+ {
+ String indirectFqn = getIndirectFqn(fqn);
+ Fqn internalFqn = getInternalFqn(fqn);
+ put(internalFqn, indirectFqn, fqn);
+ return indirectFqn;
+ }
+
+ private Fqn getInternalFqn(String fqn)
+ {
+ if (fqn == null || fqn.length() == 0)
+ throw new IllegalStateException("InternalDelegate.getInternalFqn(). fqn is
either null or empty!");
+
+ String indirectFqn = getIndirectFqn(fqn);
+ return new Fqn(InternalConstant.JBOSS_INTERNAL_MAP, indirectFqn);
+// return JBOSS_INTERNAL_MAP;
+ }
+
+ static String getIndirectFqn(String fqn)
+ {
+ // TODO This is not unique. Will need to come up with a better one in the future.
+ return ObjectUtil.getIndirectFqn(fqn);
+ }
+
+ void removeIndirectFqn(String oldFqn) throws CacheException
+ {
+ String indirectFqn = getIndirectFqn(oldFqn);
+ cache.remove(getInternalFqn(oldFqn), indirectFqn);
+ }
+
+ void setIndirectFqn(String oldFqn, String newFqn) throws CacheException
+ {
+ String indirectFqn = getIndirectFqn(oldFqn);
+ Fqn tmpFqn = getInternalFqn(oldFqn);
+ put(tmpFqn, indirectFqn, newFqn);
+ }
+
+ void updateIndirectFqn(Fqn originalFqn, Fqn newFqn) throws CacheException
+ {
+ put(getInternalFqn(originalFqn.toString()), getIndirectFqn(originalFqn.toString()),
newFqn.toString());
+ }
+
+ private String getRefFqnFromAlias(String aliasFqn) throws CacheException
+ {
+ return (String) get(getInternalFqn(aliasFqn), aliasFqn, true);
+ }
+
+ /**
+ * Test if this internal node.
+ *
+ * @param fqn
+ */
+ public static boolean isInternalNode(Fqn fqn)
+ {
+ // we ignore all the node events corresponding to JBOSS_INTERNAL
+ if (fqn.isChildOrEquals(InternalConstant.JBOSS_INTERNAL)) return true;
+
+ return false;
+ }
+
+ public boolean lockPojo(Fqn id) throws CacheException
+ {
+ final int RETRY = 5;
+
+ if (log.isTraceEnabled())
+ log.trace("lockPojo(): id:" + id);
+
+ boolean isNeeded = true;
+ int retry = 0;
+
+ while (isNeeded)
+ {
+ try
+ {
+ cache.put(id, InternalConstant.POJOCACHE_LOCK, "LOCK");
+ isNeeded = false;
+ }
+ catch (UpgradeException upe)
+ {
+ log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will
re-try. id: " + id
+ + " retry times: " + retry);
+ if (retry++ > RETRY)
+ return false;
+
+ // try to sleep a little as well.
+ try
+ {
+ Thread.sleep(10);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.Reference;
-
-/**
- * Handle the object graph management.
- *
- * @author Ben Wang
- * Date: Aug 4, 2005
- * @version $Id$
- */
-class ObjectGraphHandler extends AbstractHandler
-{
- private PojoCacheImpl cache;
- private InternalHelper internal_;
- private final static Log log = LogFactory.getLog(ObjectGraphHandler.class);
-
- public ObjectGraphHandler(PojoCacheImpl cache, InternalHelper internal)
- {
- this.cache = cache;
- internal_ = internal;
- }
-
- protected Fqn<?> getFqn(Object obj)
- {
- return null;
- }
-
- protected boolean handles(Class<?> clazz)
- {
- return false;
- }
-
- @Override
- protected Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance
pojoInstance) throws CacheException
- {
- // Note this is actually the aliasFqn, not the real fqn!
- Object obj;
-
- obj = cache.find(fqn);
- if (obj == null)
- throw new PojoCacheException("ObjectGraphHandler.get(): null object from
internal ref node." +
- " Internal ref node: " + fqn);
-
- return obj; // No need to set the instance under fqn. It is located in refFqn
anyway.
- }
-
- @Override
- protected void put(Fqn<?> fqn, Reference reference, Object obj) throws
CacheException
- {
- setupRefCounting(fqn, reference);
- }
-
- boolean isMultipleReferenced(Fqn<?> internalFqn)
- {
- // Note this is actually the aliasFqn, not the real fqn!
- PojoInstance pojoInstance = null;
- try
- {
- pojoInstance = internal_.getPojoInstance(internalFqn);
- }
- catch (CacheException e)
- {
- throw new PojoCacheException("Exception in isMultipleReferenced", e);
- }
- // check if this is a refernce
- return InternalHelper.isMultipleReferenced(pojoInstance);
-
- }
-
- @Override
- protected Object remove(Fqn<?> fqn, Reference reference, Object pojo)
- throws CacheException
- {
- if (log.isDebugEnabled())
- {
- log.debug("remove(): removing object fqn: " + reference
- + " Will just de-reference it.");
- }
- removeFromReference(fqn, reference);
-
- return null;
- }
-
- /**
- * Remove the object from the the reference fqn, meaning just decrement the ref
counter.
- */
- private void removeFromReference(Fqn<?> originalFqn, Reference reference) throws
CacheException
- {
- if (decrementRefCount(originalFqn, reference) ==
PojoInstance.INITIAL_COUNTER_VALUE)
- {
- // No one is referring it so it is safe to remove
- // TODO we should make sure the parent nodes are also removed they are empty as
well.
- cache.detach(originalFqn);
- }
- }
-
- /**
- * 1. increment reference counter
- * 2. put in refFqn so we can get it.
- *
- * @param fqn The original fqn node
- * @param refFqn The new internal fqn node
- */
- private void setupRefCounting(Fqn<?> fqn, Reference reference) throws
CacheException
- {
- // increment the reference counting
- incrementRefCount(fqn, reference);
- }
-
- private int incrementRefCount(Fqn<?> originalFqn, Reference reference) throws
CacheException
- {
- return internal_.incrementRefCount(originalFqn, reference);
- }
-
- private int decrementRefCount(Fqn<?> originalFqn, Reference reference) throws
CacheException
- {
- return internal_.decrementRefCount(originalFqn, reference);
- }
-}
Copied: pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java)
===================================================================
--- pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.Reference;
+
+/**
+ * Handle the object graph management.
+ *
+ * @author Ben Wang
+ * Date: Aug 4, 2005
+ * @version $Id$
+ */
+class ObjectGraphHandler extends AbstractHandler
+{
+ private PojoCacheImpl cache;
+ private InternalHelper internal_;
+ private final static Log log = LogFactory.getLog(ObjectGraphHandler.class);
+
+ public ObjectGraphHandler(PojoCacheImpl cache, InternalHelper internal)
+ {
+ this.cache = cache;
+ internal_ = internal;
+ }
+
+ protected Fqn<?> getFqn(Object obj)
+ {
+ return null;
+ }
+
+ protected boolean handles(Class<?> clazz)
+ {
+ return false;
+ }
+
+ @Override
+ protected Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance
pojoInstance) throws CacheException
+ {
+ // Note this is actually the aliasFqn, not the real fqn!
+ Object obj;
+
+ obj = cache.find(fqn);
+ if (obj == null)
+ throw new PojoCacheException("ObjectGraphHandler.get(): null object from
internal ref node." +
+ " Internal ref node: " + fqn);
+
+ return obj; // No need to set the instance under fqn. It is located in refFqn
anyway.
+ }
+
+ @Override
+ protected void put(Fqn<?> fqn, Reference reference, Object obj) throws
CacheException
+ {
+ setupRefCounting(fqn, reference);
+ }
+
+ boolean isMultipleReferenced(Fqn<?> internalFqn)
+ {
+ // Note this is actually the aliasFqn, not the real fqn!
+ PojoInstance pojoInstance = null;
+ try
+ {
+ pojoInstance = internal_.getPojoInstance(internalFqn);
+ }
+ catch (CacheException e)
+ {
+ throw new PojoCacheException("Exception in isMultipleReferenced", e);
+ }
+ // check if this is a refernce
+ return InternalHelper.isMultipleReferenced(pojoInstance);
+
+ }
+
+ @Override
+ protected Object remove(Fqn<?> fqn, Reference reference, Object pojo)
+ throws CacheException
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("remove(): removing object fqn: " + reference
+ + " Will just de-reference it.");
+ }
+ removeFromReference(fqn, reference);
+
+ return null;
+ }
+
+ /**
+ * Remove the object from the the reference fqn, meaning just decrement the ref
counter.
+ */
+ private void removeFromReference(Fqn<?> originalFqn, Reference reference) throws
CacheException
+ {
+ if (decrementRefCount(originalFqn, reference) ==
PojoInstance.INITIAL_COUNTER_VALUE)
+ {
+ // No one is referring it so it is safe to remove
+ // TODO we should make sure the parent nodes are also removed they are empty as
well.
+ cache.detach(originalFqn);
+ }
+ }
+
+ /**
+ * 1. increment reference counter
+ * 2. put in refFqn so we can get it.
+ *
+ * @param fqn The original fqn node
+ * @param refFqn The new internal fqn node
+ */
+ private void setupRefCounting(Fqn<?> fqn, Reference reference) throws
CacheException
+ {
+ // increment the reference counting
+ incrementRefCount(fqn, reference);
+ }
+
+ private int incrementRefCount(Fqn<?> originalFqn, Reference reference) throws
CacheException
+ {
+ return internal_.incrementRefCount(originalFqn, reference);
+ }
+
+ private int decrementRefCount(Fqn<?> originalFqn, Reference reference) throws
CacheException
+ {
+ return internal_.decrementRefCount(originalFqn, reference);
+ }
+}
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,371 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.cache.pojo.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.Advised;
-import org.jboss.aop.Advisor;
-import org.jboss.aop.InstanceAdvisor;
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.proxy.ClassProxy;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.Region;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.Reference;
-import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
-import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
-import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
-import org.jboss.cache.pojo.memory.FieldPersistentReference;
-import org.jboss.cache.pojo.util.AopUtil;
-
-import java.lang.reflect.Field;
-import java.util.*;
-
-/**
- * Delegate class for PojoCache, the real implementation code happens here.
- *
- * @author Ben Wang
- */
-public class PojoCacheDelegate
-{
- private PojoCacheImpl pojoCache;
- private Cache<Object, Object> cache;
- private final static Log log = LogFactory.getLog(PojoCacheDelegate.class);
- private InternalHelper internal_;
- private AdvisedPojoHandler advisedHandler_;
- private ObjectGraphHandler graphHandler_;
- private CollectionClassHandler collectionHandler_;
- private ArrayHandler arrayHandler;
- private SerializableObjectHandler serializableHandler_;
- // Use ThreadLocal to hold a boolean isBulkRemove
- private PojoUtil util_ = new PojoUtil();
-
- public PojoCacheDelegate(PojoCacheImpl cache)
- {
- pojoCache = cache;
- this.cache = pojoCache.getCache();
- internal_ = new InternalHelper(cache);
- graphHandler_ = new ObjectGraphHandler(pojoCache, internal_);
- collectionHandler_ = new CollectionClassHandler(pojoCache, internal_);
- serializableHandler_ = new SerializableObjectHandler(pojoCache, internal_);
- advisedHandler_ = new AdvisedPojoHandler(pojoCache, internal_, util_);
- arrayHandler = new ArrayHandler(pojoCache);
- }
-
- public Object getObject(Fqn fqn, String field, Object source) throws CacheException
- {
- // TODO Must we really to couple with BR? JBCACHE-669
- Object pojo = internal_.getPojo(fqn, field);
- if (pojo != null)
- {
- // we already have an advised instance
- if (log.isDebugEnabled())
- {
- log.debug("getObject(): id: " + fqn + " retrieved from
existing instance directly. ");
- }
- return pojo;
- }
-
- // OK. So we are here meaning that this is a failover or passivation since the
transient
- // pojo instance is not around. Let's also make sure the right classloader is
used
- // as well.
- ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
- try
- {
- Region region = cache.getRegion(fqn, false);
- if (region != null && region.getClassLoader() != null)
- Thread.currentThread().setContextClassLoader(region.getClassLoader());
-
- return getObjectInternal(fqn, field, source);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(prevCL);
- }
- }
-
- /**
- * Note that caller of this method will take care of synchronization within the
<code>fqn</code> sub-tree.
- */
- public Object putObject(Fqn fqn, Object obj, String field, Object source) throws
CacheException
- {
- internal_.lockPojo(fqn);
-
- // Skip some un-necessary update if obj is the same class as the old one
- Object oldValue = internal_.getPojo(fqn, field);
- boolean allowArray = source instanceof ArrayInterceptable;
- if (oldValue == obj && skipDuplicateAttach(obj, allowArray))
- {
- if (log.isDebugEnabled())
- {
- log.debug("putObject(): id: " + fqn + " pojo is already in the
cache. Return right away.");
- }
- return obj;
- }
-
- // remove old value before overwriting it. This is necessary to detach any
interceptor.
- // TODO Or can we simply walk thru that somewhere? Well, there is also implication
of Collection though
- pojoCache.detach(fqn, field, source);
-
- if (obj == null)
- return oldValue;// we are done
-
- AbstractHandler handler = getHandler(obj.getClass(), allowArray);
- Fqn<?> internalFqn = handler.getFqn(obj);
-
- Reference reference = new ReferenceImpl(fqn, field);
- if (internalFqn != null)
- {
- // Lock the internal fqn, before the ref count is checked
- internal_.lockPojo(internalFqn);
- graphHandler_.put(internalFqn, reference , obj);
- }
- else
- {
- internalFqn = createInternalFqn(fqn, obj);
- if (log.isDebugEnabled())
- log.debug("attach(): id: " + fqn + " will store the pojo in
the internal area: " + internalFqn);
-
- handler.put(internalFqn, reference, obj);
-
- // Used by notification sub-system
- cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS,
"ATTACHED");
- }
-
- setPojoReference(fqn, obj, field, internalFqn);
-
- return oldValue;
- }
-
- private boolean skipDuplicateAttach(Object obj, boolean allowArray)
- {
- return obj == null || getHandler(obj.getClass(), allowArray) !=
serializableHandler_;
- }
-
- private AbstractHandler getHandler(Class<?> clazz, boolean allowArray)
- {
- if (advisedHandler_.handles(clazz))
- return advisedHandler_;
-
- if (collectionHandler_.handles(clazz))
- return collectionHandler_;
-
- if (allowArray && arrayHandler.handles(clazz))
- return arrayHandler;
-
- if (serializableHandler_.handles(clazz))
- return serializableHandler_;
-
- throw new CacheException("Can not manage object. It must be either
instrumented, a collection, an array, or Serializable: "
- + clazz.getName());
- }
-
-
- private Fqn createInternalFqn(Fqn fqn, Object obj) throws CacheException
- {
- // Create an internal Fqn name
- return AopUtil.createInternalFqn(fqn, cache);
- }
-
- private Fqn setPojoReference(Fqn fqn, Object obj, String field, Fqn internalFqn)
throws CacheException
- {
- // Create PojoReference
- CachedType type = pojoCache.getCachedType(obj.getClass());
- PojoReference pojoReference = new PojoReference();
- pojoReference.setPojoClass(type.getType());
-
- // store PojoReference
- pojoReference.setFqn(internalFqn);
- internal_.putPojoReference(fqn, pojoReference, field);
- if (log.isDebugEnabled())
- {
- log.debug("put(): inserting PojoReference with id: " + fqn);
- }
- // store obj in the internal fqn
- return internalFqn;
- }
-
- private void createChildNodeFirstWithoutLocking(Fqn internalFqn)
- {
- int size = internalFqn.size();
- Fqn f = internalFqn.getSubFqn(0, size - 1);
- Fqn child = internalFqn.getSubFqn(size - 1, size);
-
- Node base = cache.getRoot().getChild(f);
- if (base == null)
- {
- log.debug("The node retrieved is null from fqn: " + f);
- return;
- }
- base.addChild(child);
- }
-
- /**
- * Note that caller of this method will take care of synchronization within the
<code>fqn</code> sub-tree.
- *
- * @param fqn
- * @return detached object
- * @throws CacheException
- */
- public Object removeObject(Fqn fqn, String field, Object source) throws
CacheException
- {
- internal_.lockPojo(fqn);
-
- // the class attribute is implicitly stored as an immutable read-only attribute
- PojoReference pojoReference = internal_.getPojoReference(fqn, field);
- if (pojoReference == null)
- {
- // clazz and pojoReference can be not null if this node is the replicated
brother node.
- if (log.isTraceEnabled())
- {
- log.trace("removeObject(): clazz is null. id: " + fqn + " No
need to remove.");
- }
- return null;
- }
-
- Fqn<?> internalFqn = pojoReference.getFqn();
-
-
-
- if (log.isDebugEnabled())
- {
- log.debug("removeObject(): removing object from id: " + fqn
- + " with the corresponding internal id: " + internalFqn);
- }
-
- Object result = pojoCache.find(internalFqn);
- if (result == null)
- return null;
-
- // Lock the internal fqn, before the ref count is checked
- internal_.lockPojo(internalFqn);
-
- Reference reference = new ReferenceImpl(fqn, field);
- if (graphHandler_.isMultipleReferenced(internalFqn))
- {
- graphHandler_.remove(internalFqn, reference, result);
- }
- else
- {
- cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS,
"DETACHING");
- boolean allowArray = source instanceof ArrayInterceptable;
- result = getHandler(result.getClass(), allowArray).remove(internalFqn,
reference, result);
- }
-
- internal_.cleanUp(fqn, field);
- return result;
- }
-
- public Map findObjects(Fqn fqn) throws CacheException
- {
-
- // Traverse from fqn to do getObject, if it return a pojo we then stop.
- Map map = new HashMap();
- Object pojo = getObject(fqn, null, null);
- if (pojo != null)
- {
- map.put(fqn, pojo);// we are done!
- return map;
- }
-
- findChildObjects(fqn, map);
- if (log.isDebugEnabled())
- {
- log.debug("_findObjects(): id: " + fqn + " size of pojos found:
" + map.size());
- }
- return map;
- }
-
- private Object getObjectInternal(Fqn<?> fqn, String field, Object source) throws
CacheException
- {
- Fqn<?> internalFqn = fqn;
- PojoReference pojoReference = internal_.getPojoReference(fqn, field);
- if (pojoReference != null)
- {
- internalFqn = pojoReference.getFqn();
- }
- else if (field != null)
- {
- return null;
- }
-
- if (log.isDebugEnabled())
- log.debug("getObject(): id: " + fqn + " with a corresponding
internal id: " + internalFqn);
-
- /**
- * Reconstruct the managed POJO
- */
- Object obj;
-
- PojoInstance pojoInstance = internal_.getPojoInstance(internalFqn);
-
- if (pojoInstance == null)
- return null;
- //throw new PojoCacheException("PojoCacheDelegate.getObjectInternal(): null
PojoInstance for fqn: " + internalFqn);
-
- Class<?> clazz = pojoInstance.getPojoClass();
- boolean allowArray = source instanceof ArrayInterceptable;
- obj = getHandler(clazz, allowArray).get(internalFqn, clazz, pojoInstance);
-
- InternalHelper.setPojo(pojoInstance, obj);
- return obj;
- }
-
- private void findChildObjects(Fqn fqn, Map map) throws CacheException
- {
- // We need to traverse then
- Node root = cache.getRoot();
- Node current = root.getChild(fqn);
-
- if (current == null) return;
-
- Collection<Node> col = current.getChildren();
- if (col == null) return;
- for (Node n : col)
- {
- Fqn newFqn = n.getFqn();
- if (InternalHelper.isInternalNode(newFqn)) continue;// skip
-
- Object pojo = getObject(newFqn, null, null);
- if (pojo != null)
- {
- map.put(newFqn, pojo);
- }
- else
- {
- findChildObjects(newFqn, map);
- }
- }
- }
-
- public boolean exists(Fqn<?> id)
- {
- return internal_.getPojoReference(id, null) != null ||
internal_.getPojoInstance(id) != null;
- }
-
- public Fqn<?> getInternalFqn(Object object)
- {
- AbstractHandler handler = getHandler(object.getClass(), true);
- Fqn<?> internalFqn = handler.getFqn(object);
- return internalFqn;
- }
-
- public Collection<Reference> getReferences(Object object)
- {
- Fqn<?> fqn = getInternalFqn(object);
- if (fqn == null)
- return Collections.emptyList();
-
- PojoInstance pojoInstance = internal_.getPojoInstance(fqn);
- return pojoInstance.getReferences();
- }
-}
Copied: pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java)
===================================================================
--- pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,372 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.pojo.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.aop.Advised;
+import org.jboss.aop.Advisor;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.proxy.ClassProxy;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.Region;
+import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.Reference;
+import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
+import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
+import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
+import org.jboss.cache.pojo.memory.FieldPersistentReference;
+import org.jboss.cache.pojo.util.AopUtil;
+
+import java.lang.reflect.Field;
+import java.util.*;
+
+/**
+ * Delegate class for PojoCache, the real implementation code happens here.
+ *
+ * @author Ben Wang
+ */
+public class PojoCacheDelegate
+{
+ private PojoCacheImpl pojoCache;
+ private Cache<Object, Object> cache;
+ private final static Log log = LogFactory.getLog(PojoCacheDelegate.class);
+ private InternalHelper internal_;
+ private AdvisedPojoHandler advisedHandler_;
+ private ObjectGraphHandler graphHandler_;
+ private CollectionClassHandler collectionHandler_;
+ private ArrayHandler arrayHandler;
+ private SerializableObjectHandler serializableHandler_;
+ // Use ThreadLocal to hold a boolean isBulkRemove
+ private PojoUtil util_ = new PojoUtil();
+
+ public PojoCacheDelegate(PojoCacheImpl cache)
+ {
+ pojoCache = cache;
+ this.cache = pojoCache.getCache();
+ internal_ = new InternalHelper(cache);
+ graphHandler_ = new ObjectGraphHandler(pojoCache, internal_);
+ collectionHandler_ = new CollectionClassHandler(pojoCache, internal_);
+ serializableHandler_ = new SerializableObjectHandler(pojoCache, internal_);
+ advisedHandler_ = new AdvisedPojoHandler(pojoCache, internal_, util_);
+ arrayHandler = new ArrayHandler(pojoCache);
+ }
+
+ public Object getObject(Fqn fqn, String field, Object source) throws CacheException
+ {
+ // TODO Must we really to couple with BR? JBCACHE-669
+ Object pojo = internal_.getPojo(fqn, field);
+ if (pojo != null)
+ {
+ // we already have an advised instance
+ if (log.isTraceEnabled())
+ {
+ log.trace("getObject(): id: " + fqn + " retrieved from
existing instance directly. ");
+ }
+ return pojo;
+ }
+
+ // OK. So we are here meaning that this is a failover or passivation since the
transient
+ // pojo instance is not around. Let's also make sure the right classloader is
used
+ // as well.
+ ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Region region = cache.getRegion(fqn, false);
+ if (region != null && region.getClassLoader() != null)
+ Thread.currentThread().setContextClassLoader(region.getClassLoader());
+
+ return getObjectInternal(fqn, field, source);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(prevCL);
+ }
+ }
+
+ /**
+ * Note that caller of this method will take care of synchronization within the
<code>fqn</code> sub-tree.
+ */
+ public Object putObject(Fqn fqn, Object obj, String field, Object source) throws
CacheException
+ {
+ internal_.lockPojo(fqn);
+
+ // Skip some un-necessary update if obj is the same class as the old one
+ Object oldValue = internal_.getPojo(fqn, field);
+ boolean allowArray = source instanceof ArrayInterceptable;
+ if (oldValue == obj && skipDuplicateAttach(obj, allowArray))
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("putObject(): id: " + fqn + " pojo is already in the
cache. Return right away.");
+ }
+ return obj;
+ }
+
+ // remove old value before overwriting it. This is necessary to detach any
interceptor.
+ // TODO Or can we simply walk thru that somewhere? Well, there is also implication
of Collection though
+ pojoCache.detach(fqn, field, source);
+
+ if (obj == null)
+ return oldValue;// we are done
+
+ AbstractHandler handler = getHandler(obj.getClass(), allowArray);
+ Fqn<?> internalFqn = handler.getFqn(obj);
+
+ Reference reference = new ReferenceImpl(fqn, field);
+ if (internalFqn != null)
+ {
+ // Lock the internal fqn, before the ref count is checked
+ internal_.lockPojo(internalFqn);
+ graphHandler_.put(internalFqn, reference , obj);
+ }
+ else
+ {
+ internalFqn = createInternalFqn(fqn, obj);
+ if (log.isTraceEnabled())
+ log.trace("attach(): id: " + fqn + " will store the pojo in
the internal area: " + internalFqn);
+
+ handler.put(internalFqn, reference, obj);
+
+ // Used by notification sub-system
+ cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS,
"ATTACHED");
+ }
+
+ setPojoReference(fqn, obj, field, internalFqn);
+
+ return oldValue;
+ }
+
+ private boolean skipDuplicateAttach(Object obj, boolean allowArray)
+ {
+ return obj == null || getHandler(obj.getClass(), allowArray) !=
serializableHandler_;
+ }
+
+ private AbstractHandler getHandler(Class<?> clazz, boolean allowArray)
+ {
+ if (advisedHandler_.handles(clazz))
+ return advisedHandler_;
+
+ if (collectionHandler_.handles(clazz))
+ return collectionHandler_;
+
+ if (allowArray && arrayHandler.handles(clazz))
+ return arrayHandler;
+
+ if (serializableHandler_.handles(clazz))
+ return serializableHandler_;
+
+ throw new CacheException("Can not manage object. It must be either
instrumented, a collection, an array, or Serializable: "
+ + clazz.getName());
+ }
+
+
+ private Fqn createInternalFqn(Fqn fqn, Object obj) throws CacheException
+ {
+ // Create an internal Fqn name
+ return AopUtil.createInternalFqn(fqn, cache);
+ }
+
+ private Fqn setPojoReference(Fqn fqn, Object obj, String field, Fqn internalFqn)
throws CacheException
+ {
+ // Create PojoReference
+ CachedType type = pojoCache.getCachedType(obj.getClass());
+ PojoReference pojoReference = new PojoReference();
+ pojoReference.setPojoClass(type.getType());
+
+ // store PojoReference
+ pojoReference.setFqn(internalFqn);
+ internal_.putPojoReference(fqn, pojoReference, field);
+ if (log.isTraceEnabled())
+ {
+ log.trace("put(): inserting PojoReference with id: " + fqn);
+ }
+ // store obj in the internal fqn
+ return internalFqn;
+ }
+
+ private void createChildNodeFirstWithoutLocking(Fqn internalFqn)
+ {
+ int size = internalFqn.size();
+ Fqn f = internalFqn.getSubFqn(0, size - 1);
+ Fqn child = internalFqn.getSubFqn(size - 1, size);
+
+ Node base = cache.getRoot().getChild(f);
+ if (base == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("The node retrieved is null from fqn: " + f);
+ return;
+ }
+ base.addChild(child);
+ }
+
+ /**
+ * Note that caller of this method will take care of synchronization within the
<code>fqn</code> sub-tree.
+ *
+ * @param fqn
+ * @return detached object
+ * @throws CacheException
+ */
+ public Object removeObject(Fqn fqn, String field, Object source) throws
CacheException
+ {
+ internal_.lockPojo(fqn);
+
+ // the class attribute is implicitly stored as an immutable read-only attribute
+ PojoReference pojoReference = internal_.getPojoReference(fqn, field);
+ if (pojoReference == null)
+ {
+ // clazz and pojoReference can be not null if this node is the replicated
brother node.
+ if (log.isTraceEnabled())
+ {
+ log.trace("removeObject(): clazz is null. id: " + fqn + " No
need to remove.");
+ }
+ return null;
+ }
+
+ Fqn<?> internalFqn = pojoReference.getFqn();
+
+
+
+ if (log.isTraceEnabled())
+ {
+ log.trace("removeObject(): removing object from id: " + fqn
+ + " with the corresponding internal id: " + internalFqn);
+ }
+
+ Object result = pojoCache.find(internalFqn);
+ if (result == null)
+ return null;
+
+ // Lock the internal fqn, before the ref count is checked
+ internal_.lockPojo(internalFqn);
+
+ Reference reference = new ReferenceImpl(fqn, field);
+ if (graphHandler_.isMultipleReferenced(internalFqn))
+ {
+ graphHandler_.remove(internalFqn, reference, result);
+ }
+ else
+ {
+ cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS,
"DETACHING");
+ boolean allowArray = source instanceof ArrayInterceptable;
+ result = getHandler(result.getClass(), allowArray).remove(internalFqn,
reference, result);
+ }
+
+ internal_.cleanUp(fqn, field);
+ return result;
+ }
+
+ public Map findObjects(Fqn fqn) throws CacheException
+ {
+
+ // Traverse from fqn to do getObject, if it return a pojo we then stop.
+ Map map = new HashMap();
+ Object pojo = getObject(fqn, null, null);
+ if (pojo != null)
+ {
+ map.put(fqn, pojo);// we are done!
+ return map;
+ }
+
+ findChildObjects(fqn, map);
+ if (log.isTraceEnabled())
+ {
+ log.trace("_findObjects(): id: " + fqn + " size of pojos found:
" + map.size());
+ }
+ return map;
+ }
+
+ private Object getObjectInternal(Fqn<?> fqn, String field, Object source) throws
CacheException
+ {
+ Fqn<?> internalFqn = fqn;
+ PojoReference pojoReference = internal_.getPojoReference(fqn, field);
+ if (pojoReference != null)
+ {
+ internalFqn = pojoReference.getFqn();
+ }
+ else if (field != null)
+ {
+ return null;
+ }
+
+ if (log.isTraceEnabled())
+ log.trace("getObject(): id: " + fqn + " with a corresponding
internal id: " + internalFqn);
+
+ /**
+ * Reconstruct the managed POJO
+ */
+ Object obj;
+
+ PojoInstance pojoInstance = internal_.getPojoInstance(internalFqn);
+
+ if (pojoInstance == null)
+ return null;
+ //throw new PojoCacheException("PojoCacheDelegate.getObjectInternal(): null
PojoInstance for fqn: " + internalFqn);
+
+ Class<?> clazz = pojoInstance.getPojoClass();
+ boolean allowArray = source instanceof ArrayInterceptable;
+ obj = getHandler(clazz, allowArray).get(internalFqn, clazz, pojoInstance);
+
+ InternalHelper.setPojo(pojoInstance, obj);
+ return obj;
+ }
+
+ private void findChildObjects(Fqn fqn, Map map) throws CacheException
+ {
+ // We need to traverse then
+ Node root = cache.getRoot();
+ Node current = root.getChild(fqn);
+
+ if (current == null) return;
+
+ Collection<Node> col = current.getChildren();
+ if (col == null) return;
+ for (Node n : col)
+ {
+ Fqn newFqn = n.getFqn();
+ if (InternalHelper.isInternalNode(newFqn)) continue;// skip
+
+ Object pojo = getObject(newFqn, null, null);
+ if (pojo != null)
+ {
+ map.put(newFqn, pojo);
+ }
+ else
+ {
+ findChildObjects(newFqn, map);
+ }
+ }
+ }
+
+ public boolean exists(Fqn<?> id)
+ {
+ return internal_.getPojoReference(id, null) != null ||
internal_.getPojoInstance(id) != null;
+ }
+
+ public Fqn<?> getInternalFqn(Object object)
+ {
+ AbstractHandler handler = getHandler(object.getClass(), true);
+ Fqn<?> internalFqn = handler.getFqn(object);
+ return internalFqn;
+ }
+
+ public Collection<Reference> getReferences(Object object)
+ {
+ Fqn<?> fqn = getInternalFqn(object);
+ if (fqn == null)
+ return Collections.emptyList();
+
+ PojoInstance pojoInstance = internal_.getPojoInstance(fqn);
+ return pojoInstance.getReferences();
+ }
+}
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,115 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.util.MethodCall;
-
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Handling the rollback operation for PojoCache level, specifically interceptor
add/remove, etc.
- *
- * @author Ben Wang
- * @version $Id$
- */
-
-public class PojoTxSynchronizationHandler implements Synchronization
-{
- private static Log log =
LogFactory.getLog(PojoTxSynchronizationHandler.class.getName());
- private List undoList_ = new ArrayList();
-
- private static ThreadLocal<PojoTxSynchronizationHandler> handler = new
ThreadLocal<PojoTxSynchronizationHandler>();
-
- PojoTxSynchronizationHandler()
- {
- }
-
- public static PojoTxSynchronizationHandler current()
- {
- return handler.get();
- }
-
- public static PojoTxSynchronizationHandler create()
- {
- PojoTxSynchronizationHandler current = handler.get();
- if (current == null)
- {
- current = new PojoTxSynchronizationHandler();
- handler.set(current);
- }
-
- return current;
- }
-
- public void beforeCompletion()
- {
- // Not interested
- }
-
- public void afterCompletion(int status)
- {
- try
- {
- switch (status)
- {
- case Status.STATUS_COMMITTED:
- break;
- case Status.STATUS_MARKED_ROLLBACK:
- case Status.STATUS_ROLLEDBACK:
- log.debug("Running Pojo rollback phase");
- runRollbackPhase();
- log.debug("Finished rollback phase");
- break;
-
- default:
- throw new IllegalStateException("illegal status: " + status);
- }
- }
- finally
- {
- resetUndoOp();
- }
- }
-
- private void runRollbackPhase()
- {
- // Rollback the pojo interceptor add/remove
- for (int i = (undoList_.size() - 1); i >= 0; i--)
- {
- MethodCall mc = (MethodCall) undoList_.get(i);
- try
- {
- mc.invoke();
- }
- catch (Throwable t)
- {
- throw new PojoCacheException(
- "PojoTxSynchronizationHandler.runRollbackPhase(): error: " +
t, t);
- }
- }
- }
-
- public void addToList(MethodCall mc)
- {
- undoList_.add(mc);
- }
-
- public void resetUndoOp()
- {
- undoList_.clear();
- handler.set(null);
- //PojoTxUndoSynchronizationInterceptor.reset();
- }
-}
-
Copied:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java)
===================================================================
---
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.interceptors;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.util.MethodCall;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Handling the rollback operation for PojoCache level, specifically interceptor
add/remove, etc.
+ *
+ * @author Ben Wang
+ * @version $Id$
+ */
+
+public class PojoTxSynchronizationHandler implements Synchronization
+{
+ private static Log log =
LogFactory.getLog(PojoTxSynchronizationHandler.class.getName());
+ private List undoList_ = new ArrayList();
+
+ private static ThreadLocal<PojoTxSynchronizationHandler> handler = new
ThreadLocal<PojoTxSynchronizationHandler>();
+
+ PojoTxSynchronizationHandler()
+ {
+ }
+
+ public static PojoTxSynchronizationHandler current()
+ {
+ return handler.get();
+ }
+
+ public static PojoTxSynchronizationHandler create()
+ {
+ PojoTxSynchronizationHandler current = handler.get();
+ if (current == null)
+ {
+ current = new PojoTxSynchronizationHandler();
+ handler.set(current);
+ }
+
+ return current;
+ }
+
+ public void beforeCompletion()
+ {
+ // Not interested
+ }
+
+ public void afterCompletion(int status)
+ {
+ try
+ {
+ switch (status)
+ {
+ case Status.STATUS_COMMITTED:
+ break;
+ case Status.STATUS_MARKED_ROLLBACK:
+ case Status.STATUS_ROLLEDBACK:
+ if (log.isTraceEnabled())
+ log.trace("Running Pojo rollback phase");
+
+ runRollbackPhase();
+
+ if (log.isTraceEnabled())
+ log.trace("Finished rollback phase");
+
+ break;
+
+ default:
+ throw new IllegalStateException("illegal status: " + status);
+ }
+ }
+ finally
+ {
+ resetUndoOp();
+ }
+ }
+
+ private void runRollbackPhase()
+ {
+ // Rollback the pojo interceptor add/remove
+ for (int i = (undoList_.size() - 1); i >= 0; i--)
+ {
+ MethodCall mc = (MethodCall) undoList_.get(i);
+ try
+ {
+ mc.invoke();
+ }
+ catch (Throwable t)
+ {
+ throw new PojoCacheException(
+ "PojoTxSynchronizationHandler.runRollbackPhase(): error: " +
t, t);
+ }
+ }
+ }
+
+ public void addToList(MethodCall mc)
+ {
+ undoList_.add(mc);
+ }
+
+ public void resetUndoOp()
+ {
+ undoList_.clear();
+ handler.set(null);
+ //PojoTxUndoSynchronizationInterceptor.reset();
+ }
+}
+
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,1033 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.cache.pojo.jmx;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.RuntimeConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.jmx.CacheJmxWrapper;
-import org.jboss.cache.jmx.CacheNotificationListener;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.impl.PojoCacheImpl;
-import org.jgroups.Channel;
-import org.jgroups.ChannelFactory;
-import org.jgroups.jmx.JChannelFactoryMBean;
-import org.w3c.dom.Element;
-
-import javax.management.AttributeChangeNotification;
-import javax.management.JMException;
-import javax.management.ListenerNotFoundException;
-import javax.management.MBeanNotificationInfo;
-import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.NotificationEmitter;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.transaction.TransactionManager;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-public class PojoCacheJmxWrapper
- implements PojoCacheJmxWrapperMBean, MBeanRegistration, NotificationEmitter
-{
- private Log log = LogFactory.getLog(getClass().getName());
-
- private boolean registerInterceptors = true;
- private Configuration config;
- private MBeanServer server;
- private String cacheObjectName;
- private PojoCache pojoCache;
- private CacheJmxWrapper plainCacheWrapper;
- private boolean registerPlainCache = true;
- private boolean plainCacheRegistered;
- private CacheStatus cacheStatus;
- private boolean registered;
- private final Set<NotificationListenerArgs> pendingListeners =
- new HashSet<NotificationListenerArgs>();
-
- // Legacy config support
-
- private Element buddyReplConfig;
- private Element evictionConfig;
- private Element cacheLoaderConfig;
- private Element clusterConfig;
- private JChannelFactoryMBean multiplexerService;
-
- /**
- * Default constructor.
- */
- public PojoCacheJmxWrapper()
- {
- cacheStatus = CacheStatus.INSTANTIATED;
- }
-
- /**
- * Creates a PojoCacheJmxWrapper that wraps the given PojoCache.
- *
- * @param toWrap the cache
- */
- public PojoCacheJmxWrapper(PojoCache toWrap)
- {
- this();
- setPojoCache(toWrap);
- }
-
- // PojoCacheMBean
-
- public PojoCache getPojoCache()
- {
- return pojoCache;
- }
-
- public Configuration getConfiguration()
- {
- Configuration cfg = (pojoCache == null ? config :
pojoCache.getCache().getConfiguration());
- if (cfg == null)
- {
- cfg = config = new Configuration();
- }
- return cfg;
- }
-
- public String getInternalLocation(Object pojo) throws
PojoCacheAlreadyDetachedException
- {
- return pojoCache.getInternalFqn(pojo).toString();
- }
-
- public String getUnderlyingCacheObjectName()
- {
- return plainCacheWrapper == null ? null : plainCacheWrapper.getCacheObjectName();
- }
-
- public void create() throws PojoCacheException
- {
- if (cacheStatus.createAllowed() == false)
- {
- if (cacheStatus.needToDestroyFailedCache())
- destroy();
- else
- return;
- }
-
- try
- {
- cacheStatus = CacheStatus.CREATING;
-
- if (pojoCache == null)
- {
- if (config == null)
- {
- throw new ConfigurationException("Must call setConfiguration() "
+
- "or setPojoCache() before call to create()");
- }
-
- constructCache();
- }
-
- pojoCache.create();
-
- registerPlainCache();
-
- plainCacheWrapper.create();
-
- cacheStatus = CacheStatus.CREATED;
- }
- catch (Throwable t)
- {
- handleLifecycleTransitionFailure(t);
- }
- }
-
- public void start() throws PojoCacheException
- {
- if (cacheStatus.startAllowed() == false)
- {
- if (cacheStatus.needToDestroyFailedCache())
- destroy();
- if (cacheStatus.needCreateBeforeStart())
- create();
- else
- return;
- }
-
- try
- {
- int oldState = getState();
- cacheStatus = CacheStatus.STARTING;
- int startingState = getState();
- sendStateChangeNotification(oldState, startingState, getClass().getSimpleName()
+ " starting", null);
-
- pojoCache.start();
-
- plainCacheWrapper.start();
- cacheStatus = CacheStatus.STARTED;
- sendStateChangeNotification(startingState, getState(),
getClass().getSimpleName() + " started", null);
- }
- catch (Throwable t)
- {
- handleLifecycleTransitionFailure(t);
- }
- }
-
- public void stop()
- {
- if (cacheStatus.stopAllowed() == false)
- {
- return;
- }
-
- // Trying to stop() from FAILED is valid, but may not work
- boolean failed = cacheStatus == CacheStatus.FAILED;
-
- try
- {
- int oldState = getState();
- cacheStatus = CacheStatus.STOPPING;
- int stoppingState = getState();
- sendStateChangeNotification(oldState, stoppingState, getClass().getSimpleName()
+ " stopping", null);
-
- cacheStatus = CacheStatus.STOPPING;
-
- pojoCache.stop();
-
- plainCacheWrapper.stop();
- cacheStatus = CacheStatus.STOPPED;
- sendStateChangeNotification(stoppingState, getState(),
getClass().getSimpleName() + " stopped", null);
- }
- catch (Throwable t)
- {
- if (failed)
- {
- log.warn("Attempted to stop() from FAILED state, " +
- "but caught exception; try calling destroy()", t);
- }
- handleLifecycleTransitionFailure(t);
- }
- }
-
- public void destroy()
- {
- if (cacheStatus.destroyAllowed() == false)
- {
- if (cacheStatus.needStopBeforeDestroy())
- stop();
- else
- return;
- }
-
- try
- {
- cacheStatus = CacheStatus.DESTROYING;
-
- if (pojoCache != null)
- pojoCache.destroy();
-
- // The cache is destroyed, so we shouldn't leave it registered
- // in JMX even if we didn't register it in create()
- unregisterPlainCache();
-
- if (plainCacheWrapper != null)
- plainCacheWrapper.destroy();
- }
- finally
- {
- // We always proceed to DESTROYED
- cacheStatus = CacheStatus.DESTROYED;
- }
- }
-
- public CacheStatus getCacheStatus()
- {
- return cacheStatus;
- }
-
- public int getState()
- {
- switch (cacheStatus)
- {
- case INSTANTIATED:
- case CREATING:
- return registered ? REGISTERED : UNREGISTERED;
- case CREATED:
- return CREATED;
- case STARTING:
- return STARTING;
- case STARTED:
- return STARTED;
- case STOPPING:
- return STOPPING;
- case STOPPED:
- case DESTROYING:
- return STOPPED;
- case DESTROYED:
- return registered ? DESTROYED : UNREGISTERED;
- case FAILED:
- default:
- return FAILED;
- }
- }
-
- public boolean getRegisterPlainCache()
- {
- return registerPlainCache;
- }
-
- public void setRegisterPlainCache(boolean registerPlainCache)
- {
- this.registerPlainCache = registerPlainCache;
- }
-
- public boolean getRegisterInterceptors()
- {
- return registerInterceptors;
- }
-
- public void setRegisterInterceptors(boolean register)
- {
- this.registerInterceptors = register;
- }
-
- // ---------------------------------------------------- LegacyConfiguration
-
- public Element getBuddyReplicationConfig()
- {
- return buddyReplConfig;
- }
-
- public Element getCacheLoaderConfig()
- {
- return cacheLoaderConfig;
- }
-
- public Element getCacheLoaderConfiguration()
- {
- return getCacheLoaderConfig();
- }
-
- public String getCacheMode()
- {
- return getConfiguration().getCacheModeString();
- }
-
- public String getClusterName()
- {
- return getConfiguration().getClusterName();
- }
-
- public String getClusterProperties()
- {
- return getConfiguration().getClusterConfig();
- }
-
- public Element getClusterConfig()
- {
- return clusterConfig;
- }
-
- public Element getEvictionPolicyConfig()
- {
- return evictionConfig;
- }
-
- public boolean getExposeManagementStatistics()
- {
- return getConfiguration().getExposeManagementStatistics();
- }
-
- public boolean getUseInterceptorMbeans()
- {
- return getExposeManagementStatistics();
- }
-
- public boolean getFetchInMemoryState()
- {
- return getConfiguration().isFetchInMemoryState();
- }
-
- public long getStateRetrievalTimeout()
- {
- return getConfiguration().getStateRetrievalTimeout();
- }
-
- @Deprecated
- public void setInitialStateRetrievalTimeout(long timeout)
- {
- setStateRetrievalTimeout(timeout);
- }
-
- public String getIsolationLevel()
- {
- return getConfiguration().getIsolationLevelString();
- }
-
- public long getLockAcquisitionTimeout()
- {
- return getConfiguration().getLockAcquisitionTimeout();
- }
-
- public JChannelFactoryMBean getMultiplexerService()
- {
- return multiplexerService;
- }
-
- public String getMultiplexerStack()
- {
- return getConfiguration().getMultiplexerStack();
- }
-
- public ChannelFactory getMuxChannelFactory()
- {
- return getConfiguration().getRuntimeConfig().getMuxChannelFactory();
- }
-
- public String getNodeLockingScheme()
- {
- return getConfiguration().getNodeLockingSchemeString();
- }
-
- public long getReplQueueInterval()
- {
- return getConfiguration().getReplQueueInterval();
- }
-
- public int getReplQueueMaxElements()
- {
- return getConfiguration().getReplQueueMaxElements();
- }
-
- public String getReplicationVersion()
- {
- return getConfiguration().getReplVersionString();
- }
-
- public boolean getSyncCommitPhase()
- {
- return getConfiguration().isSyncCommitPhase();
- }
-
- public long getSyncReplTimeout()
- {
- return getConfiguration().getSyncReplTimeout();
- }
-
- public boolean getSyncRollbackPhase()
- {
- return getConfiguration().isSyncRollbackPhase();
- }
-
- public TransactionManager getTransactionManager()
- {
- return getConfiguration().getRuntimeConfig().getTransactionManager();
- }
-
- public String getTransactionManagerLookupClass()
- {
- return getConfiguration().getTransactionManagerLookupClass();
- }
-
- public boolean getUseRegionBasedMarshalling()
- {
- return getConfiguration().isUseRegionBasedMarshalling();
- }
-
- public boolean getUseReplQueue()
- {
- return getConfiguration().isUseReplQueue();
- }
-
- public boolean isInactiveOnStartup()
- {
- return getConfiguration().isInactiveOnStartup();
- }
-
- public void setBuddyReplicationConfig(Element config)
- {
- BuddyReplicationConfig brc = null;
- if (config != null)
- {
- brc = XmlConfigurationParser.parseBuddyReplicationConfig(config);
- }
- getConfiguration().setBuddyReplicationConfig(brc);
- this.buddyReplConfig = config;
- }
-
- public void setCacheLoaderConfig(Element cache_loader_config)
- {
- CacheLoaderConfig clc = null;
- if (cache_loader_config != null)
- {
- clc = XmlConfigurationParser.parseCacheLoaderConfig(cache_loader_config);
- }
- getConfiguration().setCacheLoaderConfig(clc);
- this.cacheLoaderConfig = cache_loader_config;
- }
-
- public void setCacheLoaderConfiguration(Element config)
- {
- log.warn("MBean attribute 'CacheLoaderConfiguration' is deprecated;
" +
- "use 'CacheLoaderConfig'");
- setCacheLoaderConfig(config);
- }
-
- public void setCacheMode(String mode) throws Exception
- {
- getConfiguration().setCacheModeString(mode);
- }
-
- public void setClusterConfig(Element config)
- {
- String props = null;
- if (config != null)
- {
- props = XmlConfigurationParser.parseClusterConfigXml(config);
- }
- getConfiguration().setClusterConfig(props);
- this.clusterConfig = config;
- }
-
- @Deprecated
- public long getInitialStateRetrievalTimeout()
- {
- return getStateRetrievalTimeout();
- }
-
- public void setClusterName(String name)
- {
- getConfiguration().setClusterName(name);
- }
-
- public void setClusterProperties(String cluster_props)
- {
- getConfiguration().setClusterConfig(cluster_props);
- }
-
- public void setEvictionPolicyConfig(Element config)
- {
- EvictionConfig ec = null;
- if (config != null)
- {
- ec = XmlConfigurationParser.parseEvictionConfig(config);
- }
- getConfiguration().setEvictionConfig(ec);
- this.evictionConfig = config;
- }
-
- public void setExposeManagementStatistics(boolean expose)
- {
- getConfiguration().setExposeManagementStatistics(expose);
- }
-
- public void setUseInterceptorMbeans(boolean use)
- {
- log.warn("MBean attribute 'UseInterceptorMbeans' is deprecated; "
+
- "use 'ExposeManagementStatistics'");
- setExposeManagementStatistics(use);
- }
-
- public void setFetchInMemoryState(boolean flag)
- {
- getConfiguration().setFetchInMemoryState(flag);
- }
-
- public void setInactiveOnStartup(boolean inactiveOnStartup)
- {
- getConfiguration().setInactiveOnStartup(inactiveOnStartup);
- }
-
- public void setStateRetrievalTimeout(long timeout)
- {
- getConfiguration().setStateRetrievalTimeout(timeout);
- }
-
- public void setIsolationLevel(String level)
- {
- getConfiguration().setIsolationLevelString(level);
- }
-
- public void setLockAcquisitionTimeout(long timeout)
- {
- getConfiguration().setLockAcquisitionTimeout(timeout);
- }
-
- public void setMultiplexerService(JChannelFactoryMBean muxService)
- {
- this.multiplexerService = muxService;
- }
-
- public void setMultiplexerStack(String stackName)
- {
- getConfiguration().setMultiplexerStack(stackName);
- }
-
- public void setMuxChannelFactory(ChannelFactory factory)
- {
- getConfiguration().getRuntimeConfig().setMuxChannelFactory(factory);
- }
-
- public void setNodeLockingScheme(String nodeLockingScheme)
- {
- getConfiguration().setNodeLockingSchemeString(nodeLockingScheme);
- }
-
- public void setReplQueueInterval(long interval)
- {
- getConfiguration().setReplQueueInterval(interval);
- }
-
- public void setReplQueueMaxElements(int max_elements)
- {
- getConfiguration().setReplQueueMaxElements(max_elements);
- }
-
- public void setReplicationVersion(String version)
- {
- getConfiguration().setReplVersionString(version);
- }
-
- public void setSyncCommitPhase(boolean sync_commit_phase)
- {
- getConfiguration().setSyncCommitPhase(sync_commit_phase);
- }
-
- public void setSyncReplTimeout(long timeout)
- {
- getConfiguration().setSyncReplTimeout(timeout);
- }
-
- public void setSyncRollbackPhase(boolean sync_rollback_phase)
- {
- getConfiguration().setSyncRollbackPhase(sync_rollback_phase);
- }
-
- public void setTransactionManager(TransactionManager manager)
- {
- getConfiguration().getRuntimeConfig().setTransactionManager(manager);
- }
-
- public void setTransactionManagerLookupClass(String cl) throws Exception
- {
- getConfiguration().setTransactionManagerLookupClass(cl);
- }
-
- public void setUseRegionBasedMarshalling(boolean isTrue)
- {
- getConfiguration().setUseRegionBasedMarshalling(isTrue);
- }
-
- public void setUseReplQueue(boolean flag)
- {
- getConfiguration().setUseReplQueue(flag);
- }
-
- // ------------------------------------------------------ MBeanRegistration
-
- /**
- * Caches the provided <code>server</code> and
<code>objName</code>.
- */
- public ObjectName preRegister(MBeanServer server, ObjectName objName)
- throws Exception
- {
- this.server = server;
-
- if (cacheObjectName == null)
- {
- cacheObjectName = objName.getCanonicalName();
- }
-
- if (plainCacheWrapper != null)
- plainCacheWrapper.setNotificationServiceName(cacheObjectName);
-
- return new ObjectName(cacheObjectName);
- }
-
- /**
- * Registers the CacheJmxWrapperMBean,
- * if {@link #getRegisterPlainCache()} is <code>true</code>.
- */
- public void postRegister(Boolean registrationDone)
- {
- if (Boolean.TRUE.equals(registrationDone) && registerPlainCache)
- {
- log.debug("Registered in JMX under " + cacheObjectName);
-
- if (plainCacheWrapper != null)
- {
- try
- {
- registerPlainCache();
- }
- catch (Exception e)
- {
- log.error("Caught exception registering plain cache with JMX",
e);
- }
- }
-
- registered = true;
- }
- }
-
- /**
- * No-op.
- */
- public void preDeregister() throws Exception
- {
- }
-
- /**
- * Unregisters the CacheJmxWrapper, if {@link #getRegisterPlainCache()} is
- * <code>true</code>.
- */
- public void postDeregister()
- {
- if (plainCacheWrapper != null)
- {
- unregisterPlainCache();
- }
-
- registered = false;
- }
-
- // ---------------------------------------------------- NotificationEmitter
-
- public void removeNotificationListener(NotificationListener listener,
- NotificationFilter filter,
- Object handback)
- throws ListenerNotFoundException
- {
- synchronized (pendingListeners)
- {
- boolean found = pendingListeners.remove(new NotificationListenerArgs(listener,
filter, handback));
-
- if (plainCacheWrapper != null)
- {
- plainCacheWrapper.removeNotificationListener(listener, filter, handback);
- }
- else if (!found)
- {
- throw new ListenerNotFoundException();
- }
- }
- }
-
- public void addNotificationListener(NotificationListener listener,
- NotificationFilter filter,
- Object handback)
- throws IllegalArgumentException
- {
- synchronized (pendingListeners)
- {
- if (plainCacheWrapper != null)
- {
- plainCacheWrapper.addNotificationListener(listener, filter, handback);
- }
- else
- {
- // Add it for addition to the plainCacheWrapper when it's created
- pendingListeners.add(new NotificationListenerArgs(listener, filter,
handback));
- }
- }
-
- }
-
- public MBeanNotificationInfo[] getNotificationInfo()
- {
- return CacheNotificationListener.getNotificationInfo();
- }
-
- public void removeNotificationListener(NotificationListener listener)
- throws ListenerNotFoundException
- {
- synchronized (pendingListeners)
- {
- boolean found = false;
- for (Iterator<NotificationListenerArgs> iter =
pendingListeners.iterator();
- iter.hasNext();)
- {
- NotificationListenerArgs args = iter.next();
- if (safeEquals(listener, args.listener))
- {
- found = true;
- iter.remove();
- }
- }
-
- if (plainCacheWrapper != null)
- {
- plainCacheWrapper.removeNotificationListener(listener);
- }
- else if (!found)
- {
- throw new ListenerNotFoundException();
- }
-
- }
- }
-
- // --------------------------------------------------------- Public methods
-
- public MBeanServer getMBeanServer()
- {
- return server;
- }
-
- /**
- * Sets the configuration that the underlying cache should use.
- *
- * @param config the configuration
- */
- public void setConfiguration(Configuration config)
- {
- this.config = config;
- }
-
- public void setPojoCache(PojoCache cache)
- {
- if (cacheStatus != CacheStatus.INSTANTIATED
- && cacheStatus != CacheStatus.DESTROYED)
- throw new IllegalStateException("Cannot set underlying cache after call to
create()");
-
- this.pojoCache = cache;
- if (pojoCache == null)
- {
- this.config = null;
- this.plainCacheWrapper = null;
- }
- else
- {
- this.config = cache.getCache().getConfiguration();
- this.plainCacheWrapper = buildPlainCacheWrapper(pojoCache);
- }
- }
-
- // --------------------------------------------------------------- Private methods
-
- private void constructCache() throws ConfigurationException
- {
- pojoCache = (PojoCacheImpl) PojoCacheFactory.createCache(config, false);
-
- plainCacheWrapper = buildPlainCacheWrapper(pojoCache);
- if (multiplexerService != null)
- {
- injectMuxChannel();
- }
- }
-
- private CacheJmxWrapper buildPlainCacheWrapper(PojoCache pojoCache)
- {
- CacheJmxWrapper plainCache = new CacheJmxWrapper();
- plainCache.setRegisterInterceptors(getRegisterInterceptors());
- plainCache.setCache(pojoCache.getCache());
- // It shouldn't send out lifecycle state change notifications for itself;
- // we do it
- plainCache.setDisableStateChangeNotifications(true);
-
- if (server != null)
- {
- plainCache.setNotificationServiceName(cacheObjectName);
- }
-
- // Add any NotificationListeners we registered before creating
- // the CacheJmxWrapper
- synchronized (pendingListeners)
- {
- for (NotificationListenerArgs args : pendingListeners)
- {
- plainCache.addNotificationListener(args.listener, args.filter,
args.handback);
- }
- }
- return plainCache;
- }
-
- private boolean registerPlainCache() throws CacheException
- {
- if (registerPlainCache && !plainCacheRegistered && server != null)
- {
- try
- {
- ObjectName ourName = new ObjectName(cacheObjectName);
- ObjectName plainName = JmxUtil.getPlainCacheObjectName(ourName);
- log.debug("Registering plain cache under name " +
plainName.getCanonicalName());
- org.jboss.cache.jmx.JmxUtil.registerCacheMBean(server, plainCacheWrapper,
plainName.getCanonicalName());
- plainCacheRegistered = true;
- return true;
- }
- catch (JMException e)
- {
- throw new CacheException("Failed to register plain cache", e);
- }
- }
-
- return false;
- }
-
- private void unregisterPlainCache()
- {
- if (registerPlainCache && plainCacheRegistered && server != null)
- {
- log.debug("Unregistering plain cache");
- try
- {
- org.jboss.cache.jmx.JmxUtil.unregisterCacheMBean(server,
plainCacheWrapper.getCacheObjectName());
- }
- catch (Exception e)
- {
- log.error("Could not unregister plain cache", e);
- }
- plainCacheRegistered = false;
- }
- }
-
- private void injectMuxChannel() throws CacheException
- {
- Configuration cfg = getConfiguration();
- RuntimeConfig rtcfg = cfg.getRuntimeConfig();
-
- // Only inject if there isn't already a channel or factory
- if (rtcfg.getMuxChannelFactory() != null && rtcfg.getChannel() != null)
- {
- Channel ch;
- try
- {
- ch = multiplexerService.createMultiplexerChannel(cfg.getMultiplexerStack(),
cfg.getClusterName());
- }
- catch (Exception e)
- {
- throw new CacheException("Exception creating multiplexed channel",
e);
- }
- rtcfg.setChannel(ch);
- }
-
- }
-
- /**
- * Helper for sending out state change notifications
- */
- private void sendStateChangeNotification(int oldState, int newState, String msg,
Throwable t)
- {
- if (plainCacheWrapper != null)
- {
- long now = System.currentTimeMillis();
-
- AttributeChangeNotification stateChangeNotification = new
AttributeChangeNotification(
- this,
- plainCacheWrapper.getNextNotificationSequenceNumber(), now, msg,
- "State", "java.lang.Integer",
- new Integer(oldState), new Integer(newState)
- );
- stateChangeNotification.setUserData(t);
-
- plainCacheWrapper.sendNotification(stateChangeNotification);
- }
- }
-
- /**
- * Sets the cacheStatus to FAILED and rethrows the problem as one
- * of the declared types. Converts any non-RuntimeException Exception
- * to CacheException.
- *
- * @param t
- * @throws PojoCacheException
- * @throws RuntimeException
- * @throws Error
- */
- private void handleLifecycleTransitionFailure(Throwable t)
- throws PojoCacheException, RuntimeException, Error
- {
- int oldState = getState();
- cacheStatus = CacheStatus.FAILED;
- sendStateChangeNotification(oldState, getState(), getClass().getSimpleName() +
" failed", t);
-
- if (t instanceof PojoCacheException)
- throw (PojoCacheException) t;
- if (t instanceof CacheException)
- throw (CacheException) t;
- else if (t instanceof RuntimeException)
- throw (RuntimeException) t;
- else if (t instanceof Error)
- throw (Error) t;
- else
- throw new PojoCacheException(t);
- }
-
- private static boolean safeEquals(Object us, Object them)
- {
- return (us == null ? them == null : us.equals(them));
- }
-
- private static class NotificationListenerArgs
- {
- NotificationListener listener;
- NotificationFilter filter;
- Object handback;
-
- NotificationListenerArgs(NotificationListener listener,
- NotificationFilter filter,
- Object handback)
- {
- this.listener = listener;
- this.filter = filter;
- this.handback = handback;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj) return true;
-
- if (obj instanceof NotificationListenerArgs)
- {
- NotificationListenerArgs other = (NotificationListenerArgs) obj;
- if (safeEquals(listener, other.listener)
- && safeEquals(filter, other.filter)
- && safeEquals(handback, other.handback))
- {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- int result = 17;
- result = 29 * result + (listener != null ? listener.hashCode() : 0);
- result = 29 * result + (filter != null ? filter.hashCode() : 0);
- result = 29 * result + (handback != null ? handback.hashCode() : 0);
- return result;
- }
- }
-
-}
Copied: pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java)
===================================================================
--- pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,1036 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.cache.pojo.jmx;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.RuntimeConfig;
+import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.jmx.CacheNotificationListener;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
+import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.impl.PojoCacheImpl;
+import org.jgroups.Channel;
+import org.jgroups.ChannelFactory;
+import org.jgroups.jmx.JChannelFactoryMBean;
+import org.w3c.dom.Element;
+
+import javax.management.AttributeChangeNotification;
+import javax.management.JMException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.transaction.TransactionManager;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class PojoCacheJmxWrapper
+ implements PojoCacheJmxWrapperMBean, MBeanRegistration, NotificationEmitter
+{
+ private Log log = LogFactory.getLog(getClass().getName());
+
+ private boolean registerInterceptors = true;
+ private Configuration config;
+ private MBeanServer server;
+ private String cacheObjectName;
+ private PojoCache pojoCache;
+ private CacheJmxWrapper plainCacheWrapper;
+ private boolean registerPlainCache = true;
+ private boolean plainCacheRegistered;
+ private CacheStatus cacheStatus;
+ private boolean registered;
+ private final Set<NotificationListenerArgs> pendingListeners =
+ new HashSet<NotificationListenerArgs>();
+
+ // Legacy config support
+
+ private Element buddyReplConfig;
+ private Element evictionConfig;
+ private Element cacheLoaderConfig;
+ private Element clusterConfig;
+ private JChannelFactoryMBean multiplexerService;
+
+ /**
+ * Default constructor.
+ */
+ public PojoCacheJmxWrapper()
+ {
+ cacheStatus = CacheStatus.INSTANTIATED;
+ }
+
+ /**
+ * Creates a PojoCacheJmxWrapper that wraps the given PojoCache.
+ *
+ * @param toWrap the cache
+ */
+ public PojoCacheJmxWrapper(PojoCache toWrap)
+ {
+ this();
+ setPojoCache(toWrap);
+ }
+
+ // PojoCacheMBean
+
+ public PojoCache getPojoCache()
+ {
+ return pojoCache;
+ }
+
+ public Configuration getConfiguration()
+ {
+ Configuration cfg = (pojoCache == null ? config :
pojoCache.getCache().getConfiguration());
+ if (cfg == null)
+ {
+ cfg = config = new Configuration();
+ }
+ return cfg;
+ }
+
+ public String getInternalLocation(Object pojo) throws
PojoCacheAlreadyDetachedException
+ {
+ return pojoCache.getInternalFqn(pojo).toString();
+ }
+
+ public String getUnderlyingCacheObjectName()
+ {
+ return plainCacheWrapper == null ? null : plainCacheWrapper.getCacheObjectName();
+ }
+
+ public void create() throws PojoCacheException
+ {
+ if (cacheStatus.createAllowed() == false)
+ {
+ if (cacheStatus.needToDestroyFailedCache())
+ destroy();
+ else
+ return;
+ }
+
+ try
+ {
+ cacheStatus = CacheStatus.CREATING;
+
+ if (pojoCache == null)
+ {
+ if (config == null)
+ {
+ throw new ConfigurationException("Must call setConfiguration() "
+
+ "or setPojoCache() before call to create()");
+ }
+
+ constructCache();
+ }
+
+ pojoCache.create();
+
+ registerPlainCache();
+
+ plainCacheWrapper.create();
+
+ cacheStatus = CacheStatus.CREATED;
+ }
+ catch (Throwable t)
+ {
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ public void start() throws PojoCacheException
+ {
+ if (cacheStatus.startAllowed() == false)
+ {
+ if (cacheStatus.needToDestroyFailedCache())
+ destroy();
+ if (cacheStatus.needCreateBeforeStart())
+ create();
+ else
+ return;
+ }
+
+ try
+ {
+ int oldState = getState();
+ cacheStatus = CacheStatus.STARTING;
+ int startingState = getState();
+ sendStateChangeNotification(oldState, startingState, getClass().getSimpleName()
+ " starting", null);
+
+ pojoCache.start();
+
+ plainCacheWrapper.start();
+ cacheStatus = CacheStatus.STARTED;
+ sendStateChangeNotification(startingState, getState(),
getClass().getSimpleName() + " started", null);
+ }
+ catch (Throwable t)
+ {
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ public void stop()
+ {
+ if (cacheStatus.stopAllowed() == false)
+ {
+ return;
+ }
+
+ // Trying to stop() from FAILED is valid, but may not work
+ boolean failed = cacheStatus == CacheStatus.FAILED;
+
+ try
+ {
+ int oldState = getState();
+ cacheStatus = CacheStatus.STOPPING;
+ int stoppingState = getState();
+ sendStateChangeNotification(oldState, stoppingState, getClass().getSimpleName()
+ " stopping", null);
+
+ cacheStatus = CacheStatus.STOPPING;
+
+ pojoCache.stop();
+
+ plainCacheWrapper.stop();
+ cacheStatus = CacheStatus.STOPPED;
+ sendStateChangeNotification(stoppingState, getState(),
getClass().getSimpleName() + " stopped", null);
+ }
+ catch (Throwable t)
+ {
+ if (failed)
+ {
+ log.warn("Attempted to stop() from FAILED state, " +
+ "but caught exception; try calling destroy()", t);
+ }
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ public void destroy()
+ {
+ if (cacheStatus.destroyAllowed() == false)
+ {
+ if (cacheStatus.needStopBeforeDestroy())
+ stop();
+ else
+ return;
+ }
+
+ try
+ {
+ cacheStatus = CacheStatus.DESTROYING;
+
+ if (pojoCache != null)
+ pojoCache.destroy();
+
+ // The cache is destroyed, so we shouldn't leave it registered
+ // in JMX even if we didn't register it in create()
+ unregisterPlainCache();
+
+ if (plainCacheWrapper != null)
+ plainCacheWrapper.destroy();
+ }
+ finally
+ {
+ // We always proceed to DESTROYED
+ cacheStatus = CacheStatus.DESTROYED;
+ }
+ }
+
+ public CacheStatus getCacheStatus()
+ {
+ return cacheStatus;
+ }
+
+ public int getState()
+ {
+ switch (cacheStatus)
+ {
+ case INSTANTIATED:
+ case CREATING:
+ return registered ? REGISTERED : UNREGISTERED;
+ case CREATED:
+ return CREATED;
+ case STARTING:
+ return STARTING;
+ case STARTED:
+ return STARTED;
+ case STOPPING:
+ return STOPPING;
+ case STOPPED:
+ case DESTROYING:
+ return STOPPED;
+ case DESTROYED:
+ return registered ? DESTROYED : UNREGISTERED;
+ case FAILED:
+ default:
+ return FAILED;
+ }
+ }
+
+ public boolean getRegisterPlainCache()
+ {
+ return registerPlainCache;
+ }
+
+ public void setRegisterPlainCache(boolean registerPlainCache)
+ {
+ this.registerPlainCache = registerPlainCache;
+ }
+
+ public boolean getRegisterInterceptors()
+ {
+ return registerInterceptors;
+ }
+
+ public void setRegisterInterceptors(boolean register)
+ {
+ this.registerInterceptors = register;
+ }
+
+ // ---------------------------------------------------- LegacyConfiguration
+
+ public Element getBuddyReplicationConfig()
+ {
+ return buddyReplConfig;
+ }
+
+ public Element getCacheLoaderConfig()
+ {
+ return cacheLoaderConfig;
+ }
+
+ public Element getCacheLoaderConfiguration()
+ {
+ return getCacheLoaderConfig();
+ }
+
+ public String getCacheMode()
+ {
+ return getConfiguration().getCacheModeString();
+ }
+
+ public String getClusterName()
+ {
+ return getConfiguration().getClusterName();
+ }
+
+ public String getClusterProperties()
+ {
+ return getConfiguration().getClusterConfig();
+ }
+
+ public Element getClusterConfig()
+ {
+ return clusterConfig;
+ }
+
+ public Element getEvictionPolicyConfig()
+ {
+ return evictionConfig;
+ }
+
+ public boolean getExposeManagementStatistics()
+ {
+ return getConfiguration().getExposeManagementStatistics();
+ }
+
+ public boolean getUseInterceptorMbeans()
+ {
+ return getExposeManagementStatistics();
+ }
+
+ public boolean getFetchInMemoryState()
+ {
+ return getConfiguration().isFetchInMemoryState();
+ }
+
+ public long getStateRetrievalTimeout()
+ {
+ return getConfiguration().getStateRetrievalTimeout();
+ }
+
+ @Deprecated
+ public void setInitialStateRetrievalTimeout(long timeout)
+ {
+ setStateRetrievalTimeout(timeout);
+ }
+
+ public String getIsolationLevel()
+ {
+ return getConfiguration().getIsolationLevelString();
+ }
+
+ public long getLockAcquisitionTimeout()
+ {
+ return getConfiguration().getLockAcquisitionTimeout();
+ }
+
+ public JChannelFactoryMBean getMultiplexerService()
+ {
+ return multiplexerService;
+ }
+
+ public String getMultiplexerStack()
+ {
+ return getConfiguration().getMultiplexerStack();
+ }
+
+ public ChannelFactory getMuxChannelFactory()
+ {
+ return getConfiguration().getRuntimeConfig().getMuxChannelFactory();
+ }
+
+ public String getNodeLockingScheme()
+ {
+ return getConfiguration().getNodeLockingSchemeString();
+ }
+
+ public long getReplQueueInterval()
+ {
+ return getConfiguration().getReplQueueInterval();
+ }
+
+ public int getReplQueueMaxElements()
+ {
+ return getConfiguration().getReplQueueMaxElements();
+ }
+
+ public String getReplicationVersion()
+ {
+ return getConfiguration().getReplVersionString();
+ }
+
+ public boolean getSyncCommitPhase()
+ {
+ return getConfiguration().isSyncCommitPhase();
+ }
+
+ public long getSyncReplTimeout()
+ {
+ return getConfiguration().getSyncReplTimeout();
+ }
+
+ public boolean getSyncRollbackPhase()
+ {
+ return getConfiguration().isSyncRollbackPhase();
+ }
+
+ public TransactionManager getTransactionManager()
+ {
+ return getConfiguration().getRuntimeConfig().getTransactionManager();
+ }
+
+ public String getTransactionManagerLookupClass()
+ {
+ return getConfiguration().getTransactionManagerLookupClass();
+ }
+
+ public boolean getUseRegionBasedMarshalling()
+ {
+ return getConfiguration().isUseRegionBasedMarshalling();
+ }
+
+ public boolean getUseReplQueue()
+ {
+ return getConfiguration().isUseReplQueue();
+ }
+
+ public boolean isInactiveOnStartup()
+ {
+ return getConfiguration().isInactiveOnStartup();
+ }
+
+ public void setBuddyReplicationConfig(Element config)
+ {
+ BuddyReplicationConfig brc = null;
+ if (config != null)
+ {
+ brc = XmlConfigurationParser.parseBuddyReplicationConfig(config);
+ }
+ getConfiguration().setBuddyReplicationConfig(brc);
+ this.buddyReplConfig = config;
+ }
+
+ public void setCacheLoaderConfig(Element cache_loader_config)
+ {
+ CacheLoaderConfig clc = null;
+ if (cache_loader_config != null)
+ {
+ clc = XmlConfigurationParser.parseCacheLoaderConfig(cache_loader_config);
+ }
+ getConfiguration().setCacheLoaderConfig(clc);
+ this.cacheLoaderConfig = cache_loader_config;
+ }
+
+ public void setCacheLoaderConfiguration(Element config)
+ {
+ log.warn("MBean attribute 'CacheLoaderConfiguration' is deprecated;
" +
+ "use 'CacheLoaderConfig'");
+ setCacheLoaderConfig(config);
+ }
+
+ public void setCacheMode(String mode) throws Exception
+ {
+ getConfiguration().setCacheModeString(mode);
+ }
+
+ public void setClusterConfig(Element config)
+ {
+ String props = null;
+ if (config != null)
+ {
+ props = XmlConfigurationParser.parseClusterConfigXml(config);
+ }
+ getConfiguration().setClusterConfig(props);
+ this.clusterConfig = config;
+ }
+
+ @Deprecated
+ public long getInitialStateRetrievalTimeout()
+ {
+ return getStateRetrievalTimeout();
+ }
+
+ public void setClusterName(String name)
+ {
+ getConfiguration().setClusterName(name);
+ }
+
+ public void setClusterProperties(String cluster_props)
+ {
+ getConfiguration().setClusterConfig(cluster_props);
+ }
+
+ public void setEvictionPolicyConfig(Element config)
+ {
+ EvictionConfig ec = null;
+ if (config != null)
+ {
+ ec = XmlConfigurationParser.parseEvictionConfig(config);
+ }
+ getConfiguration().setEvictionConfig(ec);
+ this.evictionConfig = config;
+ }
+
+ public void setExposeManagementStatistics(boolean expose)
+ {
+ getConfiguration().setExposeManagementStatistics(expose);
+ }
+
+ public void setUseInterceptorMbeans(boolean use)
+ {
+ log.warn("MBean attribute 'UseInterceptorMbeans' is deprecated; "
+
+ "use 'ExposeManagementStatistics'");
+ setExposeManagementStatistics(use);
+ }
+
+ public void setFetchInMemoryState(boolean flag)
+ {
+ getConfiguration().setFetchInMemoryState(flag);
+ }
+
+ public void setInactiveOnStartup(boolean inactiveOnStartup)
+ {
+ getConfiguration().setInactiveOnStartup(inactiveOnStartup);
+ }
+
+ public void setStateRetrievalTimeout(long timeout)
+ {
+ getConfiguration().setStateRetrievalTimeout(timeout);
+ }
+
+ public void setIsolationLevel(String level)
+ {
+ getConfiguration().setIsolationLevelString(level);
+ }
+
+ public void setLockAcquisitionTimeout(long timeout)
+ {
+ getConfiguration().setLockAcquisitionTimeout(timeout);
+ }
+
+ public void setMultiplexerService(JChannelFactoryMBean muxService)
+ {
+ this.multiplexerService = muxService;
+ }
+
+ public void setMultiplexerStack(String stackName)
+ {
+ getConfiguration().setMultiplexerStack(stackName);
+ }
+
+ public void setMuxChannelFactory(ChannelFactory factory)
+ {
+ getConfiguration().getRuntimeConfig().setMuxChannelFactory(factory);
+ }
+
+ public void setNodeLockingScheme(String nodeLockingScheme)
+ {
+ getConfiguration().setNodeLockingSchemeString(nodeLockingScheme);
+ }
+
+ public void setReplQueueInterval(long interval)
+ {
+ getConfiguration().setReplQueueInterval(interval);
+ }
+
+ public void setReplQueueMaxElements(int max_elements)
+ {
+ getConfiguration().setReplQueueMaxElements(max_elements);
+ }
+
+ public void setReplicationVersion(String version)
+ {
+ getConfiguration().setReplVersionString(version);
+ }
+
+ public void setSyncCommitPhase(boolean sync_commit_phase)
+ {
+ getConfiguration().setSyncCommitPhase(sync_commit_phase);
+ }
+
+ public void setSyncReplTimeout(long timeout)
+ {
+ getConfiguration().setSyncReplTimeout(timeout);
+ }
+
+ public void setSyncRollbackPhase(boolean sync_rollback_phase)
+ {
+ getConfiguration().setSyncRollbackPhase(sync_rollback_phase);
+ }
+
+ public void setTransactionManager(TransactionManager manager)
+ {
+ getConfiguration().getRuntimeConfig().setTransactionManager(manager);
+ }
+
+ public void setTransactionManagerLookupClass(String cl) throws Exception
+ {
+ getConfiguration().setTransactionManagerLookupClass(cl);
+ }
+
+ public void setUseRegionBasedMarshalling(boolean isTrue)
+ {
+ getConfiguration().setUseRegionBasedMarshalling(isTrue);
+ }
+
+ public void setUseReplQueue(boolean flag)
+ {
+ getConfiguration().setUseReplQueue(flag);
+ }
+
+ // ------------------------------------------------------ MBeanRegistration
+
+ /**
+ * Caches the provided <code>server</code> and
<code>objName</code>.
+ */
+ public ObjectName preRegister(MBeanServer server, ObjectName objName)
+ throws Exception
+ {
+ this.server = server;
+
+ if (cacheObjectName == null)
+ {
+ cacheObjectName = objName.getCanonicalName();
+ }
+
+ if (plainCacheWrapper != null)
+ plainCacheWrapper.setNotificationServiceName(cacheObjectName);
+
+ return new ObjectName(cacheObjectName);
+ }
+
+ /**
+ * Registers the CacheJmxWrapperMBean,
+ * if {@link #getRegisterPlainCache()} is <code>true</code>.
+ */
+ public void postRegister(Boolean registrationDone)
+ {
+ if (Boolean.TRUE.equals(registrationDone) && registerPlainCache)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Registered in JMX under " + cacheObjectName);
+
+ if (plainCacheWrapper != null)
+ {
+ try
+ {
+ registerPlainCache();
+ }
+ catch (Exception e)
+ {
+ log.error("Caught exception registering plain cache with JMX",
e);
+ }
+ }
+
+ registered = true;
+ }
+ }
+
+ /**
+ * No-op.
+ */
+ public void preDeregister() throws Exception
+ {
+ }
+
+ /**
+ * Unregisters the CacheJmxWrapper, if {@link #getRegisterPlainCache()} is
+ * <code>true</code>.
+ */
+ public void postDeregister()
+ {
+ if (plainCacheWrapper != null)
+ {
+ unregisterPlainCache();
+ }
+
+ registered = false;
+ }
+
+ // ---------------------------------------------------- NotificationEmitter
+
+ public void removeNotificationListener(NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ throws ListenerNotFoundException
+ {
+ synchronized (pendingListeners)
+ {
+ boolean found = pendingListeners.remove(new NotificationListenerArgs(listener,
filter, handback));
+
+ if (plainCacheWrapper != null)
+ {
+ plainCacheWrapper.removeNotificationListener(listener, filter, handback);
+ }
+ else if (!found)
+ {
+ throw new ListenerNotFoundException();
+ }
+ }
+ }
+
+ public void addNotificationListener(NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ throws IllegalArgumentException
+ {
+ synchronized (pendingListeners)
+ {
+ if (plainCacheWrapper != null)
+ {
+ plainCacheWrapper.addNotificationListener(listener, filter, handback);
+ }
+ else
+ {
+ // Add it for addition to the plainCacheWrapper when it's created
+ pendingListeners.add(new NotificationListenerArgs(listener, filter,
handback));
+ }
+ }
+
+ }
+
+ public MBeanNotificationInfo[] getNotificationInfo()
+ {
+ return CacheNotificationListener.getNotificationInfo();
+ }
+
+ public void removeNotificationListener(NotificationListener listener)
+ throws ListenerNotFoundException
+ {
+ synchronized (pendingListeners)
+ {
+ boolean found = false;
+ for (Iterator<NotificationListenerArgs> iter =
pendingListeners.iterator();
+ iter.hasNext();)
+ {
+ NotificationListenerArgs args = iter.next();
+ if (safeEquals(listener, args.listener))
+ {
+ found = true;
+ iter.remove();
+ }
+ }
+
+ if (plainCacheWrapper != null)
+ {
+ plainCacheWrapper.removeNotificationListener(listener);
+ }
+ else if (!found)
+ {
+ throw new ListenerNotFoundException();
+ }
+
+ }
+ }
+
+ // --------------------------------------------------------- Public methods
+
+ public MBeanServer getMBeanServer()
+ {
+ return server;
+ }
+
+ /**
+ * Sets the configuration that the underlying cache should use.
+ *
+ * @param config the configuration
+ */
+ public void setConfiguration(Configuration config)
+ {
+ this.config = config;
+ }
+
+ public void setPojoCache(PojoCache cache)
+ {
+ if (cacheStatus != CacheStatus.INSTANTIATED
+ && cacheStatus != CacheStatus.DESTROYED)
+ throw new IllegalStateException("Cannot set underlying cache after call to
create()");
+
+ this.pojoCache = cache;
+ if (pojoCache == null)
+ {
+ this.config = null;
+ this.plainCacheWrapper = null;
+ }
+ else
+ {
+ this.config = cache.getCache().getConfiguration();
+ this.plainCacheWrapper = buildPlainCacheWrapper(pojoCache);
+ }
+ }
+
+ // --------------------------------------------------------------- Private methods
+
+ private void constructCache() throws ConfigurationException
+ {
+ pojoCache = (PojoCacheImpl) PojoCacheFactory.createCache(config, false);
+
+ plainCacheWrapper = buildPlainCacheWrapper(pojoCache);
+ if (multiplexerService != null)
+ {
+ injectMuxChannel();
+ }
+ }
+
+ private CacheJmxWrapper buildPlainCacheWrapper(PojoCache pojoCache)
+ {
+ CacheJmxWrapper plainCache = new CacheJmxWrapper();
+ plainCache.setRegisterInterceptors(getRegisterInterceptors());
+ plainCache.setCache(pojoCache.getCache());
+ // It shouldn't send out lifecycle state change notifications for itself;
+ // we do it
+ plainCache.setDisableStateChangeNotifications(true);
+
+ if (server != null)
+ {
+ plainCache.setNotificationServiceName(cacheObjectName);
+ }
+
+ // Add any NotificationListeners we registered before creating
+ // the CacheJmxWrapper
+ synchronized (pendingListeners)
+ {
+ for (NotificationListenerArgs args : pendingListeners)
+ {
+ plainCache.addNotificationListener(args.listener, args.filter,
args.handback);
+ }
+ }
+ return plainCache;
+ }
+
+ private boolean registerPlainCache() throws CacheException
+ {
+ if (registerPlainCache && !plainCacheRegistered && server != null)
+ {
+ try
+ {
+ ObjectName ourName = new ObjectName(cacheObjectName);
+ ObjectName plainName = JmxUtil.getPlainCacheObjectName(ourName);
+ if (log.isDebugEnabled())
+ log.debug("Registering plain cache under name " +
plainName.getCanonicalName());
+ org.jboss.cache.jmx.JmxUtil.registerCacheMBean(server, plainCacheWrapper,
plainName.getCanonicalName());
+ plainCacheRegistered = true;
+ return true;
+ }
+ catch (JMException e)
+ {
+ throw new CacheException("Failed to register plain cache", e);
+ }
+ }
+
+ return false;
+ }
+
+ private void unregisterPlainCache()
+ {
+ if (registerPlainCache && plainCacheRegistered && server != null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Unregistering plain cache");
+ try
+ {
+ org.jboss.cache.jmx.JmxUtil.unregisterCacheMBean(server,
plainCacheWrapper.getCacheObjectName());
+ }
+ catch (Exception e)
+ {
+ log.error("Could not unregister plain cache", e);
+ }
+ plainCacheRegistered = false;
+ }
+ }
+
+ private void injectMuxChannel() throws CacheException
+ {
+ Configuration cfg = getConfiguration();
+ RuntimeConfig rtcfg = cfg.getRuntimeConfig();
+
+ // Only inject if there isn't already a channel or factory
+ if (rtcfg.getMuxChannelFactory() != null && rtcfg.getChannel() != null)
+ {
+ Channel ch;
+ try
+ {
+ ch = multiplexerService.createMultiplexerChannel(cfg.getMultiplexerStack(),
cfg.getClusterName());
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Exception creating multiplexed channel",
e);
+ }
+ rtcfg.setChannel(ch);
+ }
+
+ }
+
+ /**
+ * Helper for sending out state change notifications
+ */
+ private void sendStateChangeNotification(int oldState, int newState, String msg,
Throwable t)
+ {
+ if (plainCacheWrapper != null)
+ {
+ long now = System.currentTimeMillis();
+
+ AttributeChangeNotification stateChangeNotification = new
AttributeChangeNotification(
+ this,
+ plainCacheWrapper.getNextNotificationSequenceNumber(), now, msg,
+ "State", "java.lang.Integer",
+ new Integer(oldState), new Integer(newState)
+ );
+ stateChangeNotification.setUserData(t);
+
+ plainCacheWrapper.sendNotification(stateChangeNotification);
+ }
+ }
+
+ /**
+ * Sets the cacheStatus to FAILED and rethrows the problem as one
+ * of the declared types. Converts any non-RuntimeException Exception
+ * to CacheException.
+ *
+ * @param t
+ * @throws PojoCacheException
+ * @throws RuntimeException
+ * @throws Error
+ */
+ private void handleLifecycleTransitionFailure(Throwable t)
+ throws PojoCacheException, RuntimeException, Error
+ {
+ int oldState = getState();
+ cacheStatus = CacheStatus.FAILED;
+ sendStateChangeNotification(oldState, getState(), getClass().getSimpleName() +
" failed", t);
+
+ if (t instanceof PojoCacheException)
+ throw (PojoCacheException) t;
+ if (t instanceof CacheException)
+ throw (CacheException) t;
+ else if (t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ else if (t instanceof Error)
+ throw (Error) t;
+ else
+ throw new PojoCacheException(t);
+ }
+
+ private static boolean safeEquals(Object us, Object them)
+ {
+ return (us == null ? them == null : us.equals(them));
+ }
+
+ private static class NotificationListenerArgs
+ {
+ NotificationListener listener;
+ NotificationFilter filter;
+ Object handback;
+
+ NotificationListenerArgs(NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ {
+ this.listener = listener;
+ this.filter = filter;
+ this.handback = handback;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj) return true;
+
+ if (obj instanceof NotificationListenerArgs)
+ {
+ NotificationListenerArgs other = (NotificationListenerArgs) obj;
+ if (safeEquals(listener, other.listener)
+ && safeEquals(filter, other.filter)
+ && safeEquals(handback, other.handback))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 17;
+ result = 29 * result + (listener != null ? listener.hashCode() : 0);
+ result = 29 * result + (filter != null ? filter.hashCode() : 0);
+ result = 29 * result + (handback != null ? handback.hashCode() : 0);
+ return result;
+ }
+ }
+
+}
Deleted:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java
===================================================================
---
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java 2008-10-20
21:52:11 UTC (rev 6989)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -1,142 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.cache.pojo.memory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
-import java.lang.ref.WeakReference;
-
-/**
- * Base class for persistent references.
- * Persistent reference is a Weak/Soft reference to a reflection object.
- * If the reflection object is garbage collected, the reference is then rebuilt using
reflection operations.
- *
- * @author csuconic
- */
-public abstract class PersistentReference
-{
- static final int REFERENCE_WEAK = 1;
- public static final int REFERENCE_SOFT = 2;
-
- private static final Log log = LogFactory.getLog(PersistentReference.class);
- private static final boolean isDebug = log.isDebugEnabled();
-
- private WeakReference classReference;
- private Reference referencedObject;
- private int referenceType = 0;
-
- /**
- * @param clazz The clazz being used on this object (where we will do
reflection operations)
- * @param referencedObject The reflection object being used
- * @param referenceType if REFERENCE_WEAK will use a WeakReference, and if
REFERENCE_SOFT will use a SoftReference for referencedObject
- */
- public PersistentReference(Class clazz, Object referencedObject, int referenceType)
- {
- this.referenceType = referenceType;
- if (clazz != null)
- {
- classReference = new WeakReference(clazz);
- }
- buildReference(referencedObject);
- }
-
- /**
- * Checks the reference but doesn't perform rebuild if empty
- */
- Object internalGet()
- {
- if (referencedObject == null)
- return null;
-
- return referencedObject.get();
-
-
- }
-
- public Object get()
- {
- if (referencedObject == null)
- return null;
-
- Object returnValue = referencedObject.get();
- if (returnValue == null)
- {
- try
- {
- if (isDebug) log.debug("Reference on " + this.getClass().getName()
+ " being rebuilt");
-
- // Return ths value straight from the rebuild, to guarantee the value is not
destroyed if a GC happens during the rebuild reference
- return rebuildReference();
- }
- catch (RuntimeException re)
- {
- throw re;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- return returnValue;
- }
-
- protected abstract Object rebuildReference() throws Exception;
-
- /**
- * This method should be called from a synchronized block
- */
- void buildReference(Object obj)
- {
- if (obj == null)
- {
- referencedObject = null;
- }
- else
- {
- if (referenceType == REFERENCE_WEAK)
- {
- referencedObject = new WeakReference(obj);
- }
- else
- {
- referencedObject = new SoftReference(obj);
- }
- }
- }
-
- Class getMappedClass()
- {
- if (classReference == null) return null;
- Class returnClass = (Class) classReference.get();
- if (returnClass == null)
- {
- throw new RuntimeException("Class was already unloaded");
- }
- return (Class) returnClass;
- }
-
-}
Copied:
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java
(from rev 6990,
pojo/branches/2.2/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java)
===================================================================
--- pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java
(rev 0)
+++
pojo/tags/2.2.0.GA/src/main/java/org/jboss/cache/pojo/memory/PersistentReference.java 2008-10-21
21:03:54 UTC (rev 6991)
@@ -0,0 +1,142 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.cache.pojo.memory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+
+/**
+ * Base class for persistent references.
+ * Persistent reference is a Weak/Soft reference to a reflection object.
+ * If the reflection object is garbage collected, the reference is then rebuilt using
reflection operations.
+ *
+ * @author csuconic
+ */
+public abstract class PersistentReference
+{
+ static final int REFERENCE_WEAK = 1;
+ public static final int REFERENCE_SOFT = 2;
+
+ private static final Log log = LogFactory.getLog(PersistentReference.class);
+ private static final boolean isTrace = log.isTraceEnabled();
+
+ private WeakReference classReference;
+ private Reference referencedObject;
+ private int referenceType = 0;
+
+ /**
+ * @param clazz The clazz being used on this object (where we will do
reflection operations)
+ * @param referencedObject The reflection object being used
+ * @param referenceType if REFERENCE_WEAK will use a WeakReference, and if
REFERENCE_SOFT will use a SoftReference for referencedObject
+ */
+ public PersistentReference(Class clazz, Object referencedObject, int referenceType)
+ {
+ this.referenceType = referenceType;
+ if (clazz != null)
+ {
+ classReference = new WeakReference(clazz);
+ }
+ buildReference(referencedObject);
+ }
+
+ /**
+ * Checks the reference but doesn't perform rebuild if empty
+ */
+ Object internalGet()
+ {
+ if (referencedObject == null)
+ return null;
+
+ return referencedObject.get();
+
+
+ }
+
+ public Object get()
+ {
+ if (referencedObject == null)
+ return null;
+
+ Object returnValue = referencedObject.get();
+ if (returnValue == null)
+ {
+ try
+ {
+ if (isTrace) log.trace("Reference on " + this.getClass().getName()
+ " being rebuilt");
+
+ // Return ths value straight from the rebuild, to guarantee the value is not
destroyed if a GC happens during the rebuild reference
+ return rebuildReference();
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ return returnValue;
+ }
+
+ protected abstract Object rebuildReference() throws Exception;
+
+ /**
+ * This method should be called from a synchronized block
+ */
+ void buildReference(Object obj)
+ {
+ if (obj == null)
+ {
+ referencedObject = null;
+ }
+ else
+ {
+ if (referenceType == REFERENCE_WEAK)
+ {
+ referencedObject = new WeakReference(obj);
+ }
+ else
+ {
+ referencedObject = new SoftReference(obj);
+ }
+ }
+ }
+
+ Class getMappedClass()
+ {
+ if (classReference == null) return null;
+ Class returnClass = (Class) classReference.get();
+ if (returnClass == null)
+ {
+ throw new RuntimeException("Class was already unloaded");
+ }
+ return (Class) returnClass;
+ }
+
+}