-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1081] Make connection context available for message mappers.
Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
- Loading branch information
Showing
38 changed files
with
584 additions
and
401 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
41 changes: 41 additions & 0 deletions
41
...rvice/src/main/java/org/eclipse/ditto/connectivity/service/mapping/ConnectionContext.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,41 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.connectivity.service.mapping; | ||
|
||
import org.eclipse.ditto.connectivity.model.Connection; | ||
import org.eclipse.ditto.connectivity.service.config.ConnectivityConfig; | ||
|
||
/** | ||
* Connection-related information relevant to a message mapper. | ||
*/ | ||
public interface ConnectionContext { | ||
|
||
/** | ||
* @return the connection in which the mapper is defined. | ||
*/ | ||
Connection getConnection(); | ||
|
||
/** | ||
* @return the connectivity config for the connection in which the mapper is defined. | ||
*/ | ||
ConnectivityConfig getConnectivityConfig(); | ||
|
||
/** | ||
* Create a copy of this context with a modified connectivity config. | ||
* | ||
* @param modifiedConfig the modified config. | ||
* @return the new context. | ||
*/ | ||
ConnectionContext withConnectivityConfig(ConnectivityConfig modifiedConfig); | ||
|
||
} |
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
82 changes: 82 additions & 0 deletions
82
.../src/main/java/org/eclipse/ditto/connectivity/service/mapping/DittoConnectionContext.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,82 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.connectivity.service.mapping; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.ditto.connectivity.model.Connection; | ||
import org.eclipse.ditto.connectivity.service.config.ConnectivityConfig; | ||
|
||
/** | ||
* Implementation of {@link ConnectionContext}. | ||
*/ | ||
public final class DittoConnectionContext implements ConnectionContext { | ||
|
||
private final Connection connection; | ||
private final ConnectivityConfig connectivityConfig; | ||
|
||
private DittoConnectionContext(final Connection connection, final ConnectivityConfig connectivityConfig) { | ||
this.connection = connection; | ||
this.connectivityConfig = connectivityConfig; | ||
} | ||
|
||
/** | ||
* Create a connection context from a connection and its connectivity config. | ||
* | ||
* @param connection the connection. | ||
* @param config the connectivity config. | ||
* @return the connection context. | ||
*/ | ||
public static DittoConnectionContext of(final Connection connection, final ConnectivityConfig config) { | ||
return new DittoConnectionContext(connection, config); | ||
} | ||
|
||
@Override | ||
public Connection getConnection() { | ||
return connection; | ||
} | ||
|
||
@Override | ||
public ConnectivityConfig getConnectivityConfig() { | ||
return connectivityConfig; | ||
} | ||
|
||
@Override | ||
public ConnectionContext withConnectivityConfig(final ConnectivityConfig modifiedConfig) { | ||
return new DittoConnectionContext(connection, modifiedConfig); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + | ||
"[connection=" + connection + | ||
",connectivityConfig=" + connectivityConfig + | ||
"]"; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object other) { | ||
if (other instanceof DittoConnectionContext) { | ||
final var that = (DittoConnectionContext) other; | ||
return Objects.equals(connection, that.connection) && | ||
Objects.equals(connectivityConfig, that.connectivityConfig); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(connection, connectivityConfig); | ||
} | ||
} |
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
Oops, something went wrong.