forked from eclipse-californium/californium
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce basic correlation strategy for matching responses and
requests. Replaces the isResponseRelatedToRequest in the Matcher with CorrelationStrategy.match(). Intended to be extended with a followup PR for matching messages on sending to fix issue eclipse-californium#104. Signed-off-by: Achim Kraus <achim.kraus@bosch-si.com>
- Loading branch information
Achim Kraus
committed
Jan 24, 2017
1 parent
feace05
commit 5625e2f
Showing
9 changed files
with
300 additions
and
68 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
84 changes: 84 additions & 0 deletions
84
...m-core/src/main/java/org/eclipse/californium/core/network/CorrelationStrategyFactory.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,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - introduce CorrelationStrategy | ||
* (fix GitHub issue #104) | ||
******************************************************************************/ | ||
package org.eclipse.californium.core.network; | ||
|
||
import org.eclipse.californium.core.network.config.NetworkConfig; | ||
import org.eclipse.californium.elements.CorrelationStrategy; | ||
import org.eclipse.californium.elements.RelaxedCorrelationStrategy; | ||
import org.eclipse.californium.elements.StrictlyCorrelationStrategy; | ||
|
||
/** | ||
* Factory for correlation strategy. | ||
*/ | ||
public abstract class CorrelationStrategyFactory { | ||
|
||
/** | ||
* Factory instance for correlation strategy. Default creates correlation | ||
* strategy according the configuration. If USE_STRICT_RESPONSE_MATCHING is | ||
* set, use {@link StrictlyCorrelationStrategy}, otherwise | ||
* {@link RelaxedCorrelationStrategy}. | ||
*/ | ||
private static CorrelationStrategyFactory factory = new CorrelationStrategyFactory() { | ||
|
||
protected CorrelationStrategy createStrategy(NetworkConfig config) { | ||
return config.getBoolean(NetworkConfig.Keys.USE_STRICT_RESPONSE_MATCHING) ? new StrictlyCorrelationStrategy() | ||
: new RelaxedCorrelationStrategy(); | ||
} | ||
}; | ||
|
||
/** | ||
* Create correlation strategy based on configuration. | ||
* | ||
* @param config configuration | ||
* @return correlation strategy | ||
*/ | ||
protected abstract CorrelationStrategy createStrategy(NetworkConfig config); | ||
|
||
/** | ||
* Replace the strategy factory with a custom factory. | ||
* | ||
* @param newFactory new correlation strategy factory. If null, the current | ||
* factory is not replaced and just the old one returned. | ||
* @return old strategy factory | ||
*/ | ||
public static synchronized CorrelationStrategyFactory replaceFactory(CorrelationStrategyFactory newFactory) { | ||
CorrelationStrategyFactory oldFactory = factory; | ||
if (null != newFactory) { | ||
factory = newFactory; | ||
} | ||
return oldFactory; | ||
} | ||
|
||
/** | ||
* Get the current factory. | ||
* | ||
* @return strategy factory | ||
*/ | ||
private static synchronized CorrelationStrategyFactory getFactory() { | ||
return factory; | ||
} | ||
|
||
/** | ||
* Create correlation strategy according the configuration. | ||
* | ||
* @param config configuration. | ||
* @return correlation strategy | ||
*/ | ||
public static CorrelationStrategy create(NetworkConfig config) { | ||
return getFactory().createStrategy(config); | ||
} | ||
} |
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
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
42 changes: 42 additions & 0 deletions
42
element-connector/src/main/java/org/eclipse/californium/elements/CorrelationStrategy.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,42 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - add flexible correlation context matching | ||
* (fix GitHub issue #104) | ||
******************************************************************************/ | ||
package org.eclipse.californium.elements; | ||
|
||
/** | ||
* Interface for correlation context processing. Enable implementor to flexible | ||
* decide on context correlation information. | ||
*/ | ||
public interface CorrelationStrategy { | ||
|
||
/** | ||
* Return strategy name. Used for logging. | ||
* | ||
* @return name of strategy. | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Check, if responses is related to the request. | ||
* | ||
* @param requestContext correlation context of request | ||
* @param responseContext correlation context of response | ||
* @return true, if response is related to the request, false, if response | ||
* should not be considered for this request. | ||
*/ | ||
boolean isResponseRelatedToRequest(CorrelationContext requestContext, CorrelationContext responseContext); | ||
|
||
} |
Oops, something went wrong.