Skip to content

Commit

Permalink
Fix Revision Deployment failed with an error
Browse files Browse the repository at this point in the history
  • Loading branch information
thisaltennakoon committed Mar 6, 2024
1 parent fe97c09 commit 1e80d6c
Showing 1 changed file with 88 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import java.util.Set;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Stream;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -194,7 +196,7 @@ public class SynapseConfiguration implements ManagedLifecycle, SynapseArtifact {
*/
private Map<String, MessageProcessor> messageProcessors = new ConcurrentHashMap<String, MessageProcessor>();

private Map<String, Object> locks = new ConcurrentHashMap<String, Object>();
private Map<String, ReadWriteLock> locks = new ConcurrentHashMap<String, ReadWriteLock>();

/**
* Endpoint templates to create actual endpoints
Expand Down Expand Up @@ -1015,35 +1017,45 @@ public Object getEntry(String key) {
* @return its value
*/
public Entry getEntryDefinition(String key) {
Object o = localRegistry.get(key);
if (o == null || o instanceof Entry) {
if (o == null) {
// this is not a local definition
synchronized (this) {
o = localRegistry.get(key);
Object lockObj = acquireLock(key);
if (lockObj instanceof ReadWriteLock) {
ReadWriteLock lock = (ReadWriteLock) lockObj;
lock.readLock().lock();
try {
Object o = localRegistry.get(key);
if (o == null || o instanceof Entry) {
if (o == null) {
Entry entry = new Entry(key);
entry.setType(Entry.REMOTE_ENTRY);
addEntry(key, entry);
return entry;
} else {
if (!(o instanceof Entry)) {
if (log.isDebugEnabled()) {
log.debug("There is no local registry entry for key : " + key +
", Object already exists of type :" + o.getClass().getName());
// this is not a local definition
synchronized (this) {
o = localRegistry.get(key);
if (o == null) {
Entry entry = new Entry(key);
entry.setType(Entry.REMOTE_ENTRY);
addEntry(key, entry);
return entry;
} else {
if (!(o instanceof Entry)) {
if (log.isDebugEnabled()) {
log.debug("There is no local registry entry for key : " + key +
", Object already exists of type :" + o.getClass().getName());
}
return null;
}
}
return null;
}
}
return (Entry) o;
} else {
if (log.isDebugEnabled()) {
log.debug("There is no local registry entry for key : " + key);
}
return null;
}
} finally {
lock.readLock().unlock();
}
return (Entry) o;
} else {
if (log.isDebugEnabled()) {
log.debug("There is no local registry entry for key : " + key);
}
return null;
}
return null;
}

/**
Expand Down Expand Up @@ -1150,12 +1162,12 @@ public Map<String, Endpoint> getDefinedEndpoints() {
}

public Object acquireLock(String key) {
Object lock = locks.get(key);
ReadWriteLock lock = locks.get(key);
if (lock == null) {
synchronized (this) {
lock = locks.get(key);
if (lock == null) {
lock = new Object();
lock = new ReentrantReadWriteLock();
locks.put(key, lock);
}
}
Expand All @@ -1171,60 +1183,68 @@ public Object acquireLock(String key) {
*/
public Endpoint getEndpoint(String key) {

synchronized (acquireLock(key)) {
Object o = getEntry(key);
if (o != null && o instanceof Endpoint) {
return (Endpoint) o;
}
Object lockObj = acquireLock(key);
if (lockObj instanceof ReadWriteLock) {
ReadWriteLock lock = (ReadWriteLock) lockObj;
lock.readLock().lock();
try {
Object o = getEntry(key);
if (o != null && o instanceof Endpoint) {
return (Endpoint) o;
}

Entry entry = null;
if (o == null) {
entry = new Entry(key);
entry.setType(Entry.REMOTE_ENTRY);
} else {
Object object = localRegistry.get(key);
if (object instanceof Entry) {
entry = (Entry) object;
Entry entry = null;
if (o == null) {
entry = new Entry(key);
entry.setType(Entry.REMOTE_ENTRY);
} else {
Object object = localRegistry.get(key);
if (object instanceof Entry) {
entry = (Entry) object;
}
}
}

assertEntryNull(entry, key);
assertEntryNull(entry, key);

//noinspection ConstantConditions
if (entry.getMapper() == null) {
entry.setMapper(XMLToEndpointMapper.getInstance());
}
//noinspection ConstantConditions
if (entry.getMapper() == null) {
entry.setMapper(XMLToEndpointMapper.getInstance());
}

if (entry.getType() == Entry.REMOTE_ENTRY) {
if (registry != null) {
o = registry.getResource(entry, getProperties());
if (o != null && o instanceof Endpoint) {
localRegistry.put(key, entry);
return (Endpoint) o;
} else if (o instanceof OMNode) {
properties.put(SynapseConstants.SYNAPSE_CONFIGURATION, this);
Endpoint e = (Endpoint) XMLToEndpointMapper.getInstance().
getObjectFromOMNode((OMNode) o, properties);
if (e != null) {
entry.setValue(e);
return e;
if (entry.getType() == Entry.REMOTE_ENTRY) {
if (registry != null) {
o = registry.getResource(entry, getProperties());
if (o != null && o instanceof Endpoint) {
localRegistry.put(key, entry);
return (Endpoint) o;
} else if (o instanceof OMNode) {
properties.put(SynapseConstants.SYNAPSE_CONFIGURATION, this);
Endpoint e = (Endpoint) XMLToEndpointMapper.getInstance().
getObjectFromOMNode((OMNode) o, properties);
if (e != null) {
entry.setValue(e);
return e;
}
}
}
}
} else {
Object value = entry.getValue();
if (value instanceof OMNode) {
properties.put(SynapseConstants.SYNAPSE_CONFIGURATION, this);
Object object = entry.getMapper().getObjectFromOMNode(
(OMNode) value, getProperties());
if (object instanceof Endpoint) {
entry.setValue(object);
return (Endpoint) object;
} else {
Object value = entry.getValue();
if (value instanceof OMNode) {
properties.put(SynapseConstants.SYNAPSE_CONFIGURATION, this);
Object object = entry.getMapper().getObjectFromOMNode(
(OMNode) value, getProperties());
if (object instanceof Endpoint) {
entry.setValue(object);
return (Endpoint) object;
}
}
}
return null;
} finally {
lock.readLock().unlock();
}
return null;
}
return null;
}

/**
Expand Down

0 comments on commit 1e80d6c

Please sign in to comment.