mirror of
https://github.com/apache/activemq.git
synced 2025-02-06 01:59:15 +00:00
Reduce contention by using an Atomic Reference.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@633570 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c8cfd9cfe
commit
c84e58a948
@ -19,6 +19,8 @@ package org.apache.activemq.broker;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.apache.activemq.broker.region.Destination;
|
import org.apache.activemq.broker.region.Destination;
|
||||||
import org.apache.activemq.broker.region.MessageReference;
|
import org.apache.activemq.broker.region.MessageReference;
|
||||||
import org.apache.activemq.broker.region.Subscription;
|
import org.apache.activemq.broker.region.Subscription;
|
||||||
@ -49,30 +51,25 @@ import org.apache.activemq.kaha.Store;
|
|||||||
*/
|
*/
|
||||||
public class MutableBrokerFilter implements Broker {
|
public class MutableBrokerFilter implements Broker {
|
||||||
|
|
||||||
private Broker next;
|
private AtomicReference<Broker> next = new AtomicReference<Broker>();
|
||||||
private final Object mutext = new Object();
|
|
||||||
|
|
||||||
public MutableBrokerFilter(Broker next) {
|
public MutableBrokerFilter(Broker next) {
|
||||||
this.next = next;
|
this.next.set(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Broker getAdaptor(Class type) {
|
public Broker getAdaptor(Class type) {
|
||||||
if (type.isInstance(this)) {
|
if (type.isInstance(this)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
return next.getAdaptor(type);
|
return next.get().getAdaptor(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Broker getNext() {
|
public Broker getNext() {
|
||||||
synchronized (mutext) {
|
return next.get();
|
||||||
return next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNext(Broker next) {
|
public void setNext(Broker next) {
|
||||||
synchronized (mutext) {
|
this.next.set(next);
|
||||||
this.next = next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<ActiveMQDestination, Destination> getDestinationMap() {
|
public Map<ActiveMQDestination, Destination> getDestinationMap() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user