Skip to content

Commit

Permalink
Some synchronized comments clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Jun 21, 2023
1 parent c38ed96 commit a147040
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void setAdditionalPropertiesCallback(@Nullable Function<NamedComponent,
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext().equals(this.applicationContext)) {
buildGraph();
rebuild();
}
}

Expand All @@ -132,7 +132,7 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
* @see #rebuild()
*/
public Graph getGraph() {
if (this.graph == null) { // NOSONAR (sync)
if (this.graph == null) {
this.lock.lock();
try {
if (this.graph == null) {
Expand All @@ -153,7 +153,13 @@ public Graph getGraph() {
* @see #getGraph()
*/
public Graph rebuild() {
return buildGraph();
this.lock.lock();
try {
return buildGraph();
}
finally {
this.lock.unlock();
}
}

/**
Expand All @@ -170,7 +176,7 @@ protected <T> Map<String, T> getBeansOfType(Class<T> type) {
}

private <T extends IntegrationNode> T enhance(T node) {
if (this.micrometerEnhancer != null) { // NOSONAR - synchronized inconsistency
if (this.micrometerEnhancer != null) {
return this.micrometerEnhancer.enhance(node);
}
else {
Expand All @@ -179,40 +185,34 @@ private <T extends IntegrationNode> T enhance(T node) {
}

private Graph buildGraph() {
this.lock.lock();
try {
if (this.micrometerEnhancer == null && MicrometerMetricsCaptorConfiguration.METER_REGISTRY_PRESENT) {
this.micrometerEnhancer = new MicrometerNodeEnhancer(this.applicationContext);
}
String implementationVersion = IntegrationGraphServer.class.getPackage().getImplementationVersion();
if (implementationVersion == null) {
implementationVersion = "unknown - is Spring Integration running from the distribution jar?";
}
Map<String, Object> descriptor = new HashMap<>();
descriptor.put("provider", "spring-integration");
descriptor.put("providerVersion", implementationVersion);
descriptor.put("providerFormatVersion", GRAPH_VERSION);
String name = this.applicationName;
if (name == null) {
name = this.applicationContext.getEnvironment().getProperty("spring.application.name");
}
if (name != null) {
descriptor.put("name", name);
}
this.nodeFactory.reset();
Collection<IntegrationNode> nodes = new ArrayList<>();
Collection<LinkNode> links = new ArrayList<>();
Map<String, MessageChannelNode> channelNodes = channels(nodes);
pollingAdapters(nodes, links, channelNodes);
gateways(nodes, links, channelNodes);
producers(nodes, links, channelNodes);
consumers(nodes, links, channelNodes);
this.graph = new Graph(descriptor, nodes, links);
return this.graph;
if (this.micrometerEnhancer == null && MicrometerMetricsCaptorConfiguration.METER_REGISTRY_PRESENT) {
this.micrometerEnhancer = new MicrometerNodeEnhancer(this.applicationContext);
}
finally {
this.lock.unlock();
String implementationVersion = IntegrationGraphServer.class.getPackage().getImplementationVersion();
if (implementationVersion == null) {
implementationVersion = "unknown - is Spring Integration running from the distribution jar?";
}
Map<String, Object> descriptor = new HashMap<>();
descriptor.put("provider", "spring-integration");
descriptor.put("providerVersion", implementationVersion);
descriptor.put("providerFormatVersion", GRAPH_VERSION);
String name = this.applicationName;
if (name == null) {
name = this.applicationContext.getEnvironment().getProperty("spring.application.name");
}
if (name != null) {
descriptor.put("name", name);
}
this.nodeFactory.reset();
Collection<IntegrationNode> nodes = new ArrayList<>();
Collection<LinkNode> links = new ArrayList<>();
Map<String, MessageChannelNode> channelNodes = channels(nodes);
pollingAdapters(nodes, links, channelNodes);
gateways(nodes, links, channelNodes);
producers(nodes, links, channelNodes);
consumers(nodes, links, channelNodes);
this.graph = new Graph(descriptor, nodes, links);
return this.graph;
}

private Map<String, MessageChannelNode> channels(Collection<IntegrationNode> nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ private void parseScriptIfNecessary(ScriptSource scriptSource) {
if (this.scriptClass == null || scriptSource.isModified()) {
this.scriptLock.lock();
try {
// synchronized double check
if (this.scriptClass == null || scriptSource.isModified()) {
String className = scriptSource.suggestedClassName();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ private boolean dataAvailable() {

/**
* Blocks until a complete message has been assembled.
* Synchronized to avoid concurrency.
* @return The Message or null if no data is available.
* @throws IOException an IO exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public String getComponentType() {
}

protected void incrementClientInstance() {
this.clientInstance++; //NOSONAR - false positive - called from synchronized block
this.clientInstance++;
}

/**
Expand All @@ -291,7 +291,7 @@ protected void incrementClientInstance() {
* @since 4.1
*/
public void setCompletionTimeout(long completionTimeout) {
this.completionTimeout = completionTimeout; // NOSONAR (sync)
this.completionTimeout = completionTimeout;
}

protected long getCompletionTimeout() {
Expand All @@ -305,7 +305,7 @@ protected long getCompletionTimeout() {
* @since 5.1.10
*/
public void setDisconnectCompletionTimeout(long completionTimeout) {
this.disconnectCompletionTimeout = completionTimeout; // NOSONAR (sync)
this.disconnectCompletionTimeout = completionTimeout;
}

protected long getDisconnectCompletionTimeout() {
Expand Down

0 comments on commit a147040

Please sign in to comment.