Skip to content

Commit

Permalink
Extract org.wildfly.clustering.ee.cache module from org.wildfly.clust…
Browse files Browse the repository at this point in the history
…ering.ee.infinispan module to be consumed by org.wildfly.clustering.ee.hotrod

Extract org.wildfly.clustering.web.cache module from org.wildfly.clustering.web.infinispan module to be consumed by org.wildfly.clustering.web.hotrod
  • Loading branch information
pferraro committed May 22, 2019
1 parent ad50730 commit afed634
Show file tree
Hide file tree
Showing 111 changed files with 599 additions and 286 deletions.
60 changes: 60 additions & 0 deletions clustering/ee/cache/pom.xml
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., 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.
-->

<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>

<parent>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-ee</artifactId>
<!--
Maintain separation between the artifact id and the version to help prevent
merge conflicts between commits changing the GA and those changing the V.
-->
<version>17.0.0.Beta1-SNAPSHOT</version>
</parent>

<artifactId>wildfly-clustering-ee-cache</artifactId>
<packaging>jar</packaging>

<name>WildFly: Common EE implementations for caches</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-ee-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Expand Up @@ -20,7 +20,7 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.clustering.ee.infinispan;
package org.wildfly.clustering.ee.cache;

/**
* Exposes a cache configuration as simple high-level properties.
Expand Down
Expand Up @@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.ee.retry;
package org.wildfly.clustering.ee.cache.retry;

import java.time.Duration;
import java.util.Arrays;
Expand Down
Expand Up @@ -20,7 +20,7 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.clustering.ee.infinispan;
package org.wildfly.clustering.ee.cache.tx;

import javax.transaction.Transaction;

Expand Down
Expand Up @@ -19,9 +19,10 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.ee.infinispan;
package org.wildfly.clustering.ee.cache.tx;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
Expand All @@ -30,21 +31,21 @@
import javax.transaction.SystemException;
import javax.transaction.Transaction;

import org.infinispan.commons.CacheException;

/**
* Abstract {@link TransactionBatch} that associates and exposes the underlying transaction.
* @author Paul Ferraro
*/
public class InfinispanBatch implements TransactionBatch {
public class TransactionalBatch<E extends RuntimeException> implements TransactionBatch {

private final Function<Throwable, E> exceptionTransformer;
private final Transaction tx;
private final AtomicInteger count = new AtomicInteger(0);

private volatile boolean active = true;

public InfinispanBatch(Transaction tx) {
public TransactionalBatch(Transaction tx, Function<Throwable, E> exceptionTransformer) {
this.tx = tx;
this.exceptionTransformer = exceptionTransformer;
}

@Override
Expand Down Expand Up @@ -82,7 +83,7 @@ public State getState() {
}
}
} catch (SystemException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
}
}

Expand All @@ -99,7 +100,7 @@ public void close() {
} catch (RollbackException e) {
throw new IllegalStateException(e);
} catch (HeuristicMixedException | HeuristicRollbackException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
}
}
// Otherwise fall through
Expand All @@ -110,7 +111,7 @@ public void close() {
}
}
} catch (SystemException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
}
}
}
Expand All @@ -122,8 +123,8 @@ public int hashCode() {

@Override
public boolean equals(Object object) {
if (!(object instanceof InfinispanBatch)) return false;
InfinispanBatch batch = (InfinispanBatch) object;
if (!(object instanceof TransactionalBatch)) return false;
TransactionalBatch<?> batch = (TransactionalBatch<?>) object;
return this.tx.equals(batch.tx);
}

Expand Down
Expand Up @@ -19,7 +19,9 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.ee.infinispan;
package org.wildfly.clustering.ee.cache.tx;

import java.util.function.Function;

import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
Expand All @@ -29,8 +31,6 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;

import org.infinispan.Cache;
import org.infinispan.commons.CacheException;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.ee.BatchContext;
import org.wildfly.clustering.ee.Batcher;
Expand All @@ -42,7 +42,7 @@
* via {@link #resumeBatch(TransactionBatch)}.
* @author Paul Ferraro
*/
public class InfinispanBatcher implements Batcher<TransactionBatch> {
public class TransactionalBatcher<E extends RuntimeException> implements Batcher<TransactionBatch> {

private static final BatchContext PASSIVE_BATCH_CONTEXT = () -> {
// Do nothing
Expand Down Expand Up @@ -103,13 +103,11 @@ public void afterCompletion(int status) {
};

private final TransactionManager tm;
private final Function<Throwable, E> exceptionTransformer;

public InfinispanBatcher(Cache<?, ?> cache) {
this(cache.getAdvancedCache().getTransactionManager());
}

public InfinispanBatcher(TransactionManager tm) {
public TransactionalBatcher(TransactionManager tm, Function<Throwable, E> exceptionTransformer) {
this.tm = tm;
this.exceptionTransformer = exceptionTransformer;
}

@Override
Expand All @@ -124,11 +122,11 @@ public TransactionBatch createBatch() {
this.tm.begin();
Transaction tx = this.tm.getTransaction();
tx.registerSynchronization(CURRENT_BATCH_SYNCHRONIZATION);
batch = new InfinispanBatch(tx);
batch = new TransactionalBatch<>(tx, this.exceptionTransformer);
setCurrentBatch(batch);
return batch;
} catch (RollbackException | SystemException | NotSupportedException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
}
}

Expand Down Expand Up @@ -159,17 +157,17 @@ public BatchContext resumeBatch(TransactionBatch batch) {
try {
this.tm.resume(existingBatch.getTransaction());
} catch (InvalidTransactionException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
}
}
} catch (SystemException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
} finally {
setCurrentBatch(existingBatch);
}
};
} catch (SystemException | InvalidTransactionException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
}
}

Expand All @@ -184,7 +182,7 @@ public TransactionBatch suspendBatch() {
throw new IllegalStateException();
}
} catch (SystemException e) {
throw new CacheException(e);
throw this.exceptionTransformer.apply(e);
} finally {
setCurrentBatch(null);
}
Expand Down
Expand Up @@ -20,7 +20,7 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.clustering.ee.retry;
package org.wildfly.clustering.ee.cache.retry;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
Expand Down

0 comments on commit afed634

Please sign in to comment.