-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JBPM-9696] ClusteredRuntimeManagerLockFactory based on infinispan
- Loading branch information
1 parent
dd9f0ea
commit c623b33
Showing
7 changed files
with
188 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../src/main/java/org/kie/server/services/jbpm/cluster/lock/ClusteredRuntimeManagerLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2021 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.server.services.jbpm.cluster.lock; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.infinispan.lock.api.ClusteredLockManager; | ||
import org.jbpm.runtime.manager.spi.RuntimeManagerLock; | ||
import org.jgroups.util.UUID; | ||
|
||
|
||
public class ClusteredRuntimeManagerLock implements RuntimeManagerLock { | ||
|
||
private String clusteredLockId; | ||
|
||
private ClusteredLockManager clusteredLockManager; | ||
|
||
public ClusteredRuntimeManagerLock(ClusteredLockManager clusteredLockManager) { | ||
this.clusteredLockManager = clusteredLockManager; | ||
clusteredLockId = UUID.randomUUID().toString(); | ||
this.clusteredLockManager.defineLock(clusteredLockId); | ||
} | ||
|
||
@Override | ||
public void lock() { | ||
clusteredLockManager.get(clusteredLockId).lock(); | ||
} | ||
|
||
@Override | ||
public boolean tryLock(long units, TimeUnit milliseconds) throws InterruptedException { | ||
try { | ||
return clusteredLockManager.get(clusteredLockId).tryLock(units, milliseconds).get(); | ||
} catch(ExecutionException e) { | ||
if(e.getCause() instanceof InterruptedException) { | ||
throw (InterruptedException) e.getCause(); | ||
} else { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void lockInterruptible() throws InterruptedException { | ||
throw new UnsupportedOperationException("this lock does not support interruptible lock"); | ||
} | ||
|
||
@Override | ||
public void forceUnlock() { | ||
try { | ||
clusteredLockManager.forceRelease(clusteredLockId).get(); | ||
} catch(Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void unlock() { | ||
try { | ||
clusteredLockManager.get(clusteredLockId).unlock().get(); | ||
} catch(Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasQueuedThreads() { | ||
try { | ||
return clusteredLockManager.get(clusteredLockId).isLocked().get(); | ||
} catch(Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isHeldByCurrentThread() { | ||
try { | ||
return clusteredLockManager.get(clusteredLockId).isLockedByMe().get(); | ||
} catch(Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public int getQueueLength() { | ||
try { | ||
return clusteredLockManager.get(clusteredLockId).isLocked().get() ? 0 : 1; | ||
} catch(Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...in/java/org/kie/server/services/jbpm/cluster/lock/ClusteredRuntimeManagerLockFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2021 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.server.services.jbpm.cluster.lock; | ||
|
||
import javax.naming.Context; | ||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
|
||
import org.infinispan.lock.EmbeddedClusteredLockManagerFactory; | ||
import org.infinispan.lock.api.ClusteredLockManager; | ||
import org.jbpm.runtime.manager.spi.RuntimeManagerLock; | ||
import org.jbpm.runtime.manager.spi.RuntimeManagerLockFactory; | ||
import org.kie.server.services.jbpm.cluster.EJBCacheBean; | ||
|
||
public class ClusteredRuntimeManagerLockFactory implements RuntimeManagerLockFactory { | ||
|
||
private EJBCacheBean mbean; | ||
|
||
private ClusteredLockManager clusterecLockManager; | ||
|
||
public ClusteredRuntimeManagerLockFactory() { | ||
try { | ||
Context context = new InitialContext(); | ||
mbean = (EJBCacheBean) context.lookup("java:global/EJBCacheBean"); | ||
clusterecLockManager = EmbeddedClusteredLockManagerFactory.from(mbean.getCacheContainer()); | ||
} catch (NamingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public RuntimeManagerLock newRuntimeManagerLock() { | ||
return new ClusteredRuntimeManagerLock(clusterecLockManager); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...c/main/resources/META-INF/services/org.jbpm.runtime.manager.spi.RuntimeManagerLockFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.kie.server.services.jbpm.cluster.lock.ClusteredRuntimeManagerLockFactory |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters