forked from O2-Czech-Republic/proxima-platform
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…d TransactionMonitoringPolicy
- Loading branch information
Showing
6 changed files
with
182 additions
and
14 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
77 changes: 77 additions & 0 deletions
77
...core/src/main/java/cz/o2/proxima/direct/core/transaction/TransactionMonitoringPolicy.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,77 @@ | ||
/* | ||
* Copyright 2017-2024 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.direct.core.transaction; | ||
|
||
import cz.o2.proxima.core.transaction.Request; | ||
import cz.o2.proxima.core.transaction.Response; | ||
import cz.o2.proxima.core.transaction.State; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* Policy that can be specified for monitoring transactions during execution. Implementing classes | ||
* should take care of performance. This class is required to be thread-safe. | ||
*/ | ||
@ThreadSafe | ||
public interface TransactionMonitoringPolicy { | ||
|
||
static TransactionMonitoringPolicy nop() { | ||
return new TransactionMonitoringPolicy() { | ||
@Override | ||
public void incomingRequest( | ||
String transactionId, Request request, long timestamp, long watermark) { | ||
// nop | ||
} | ||
|
||
@Override | ||
public void stateUpdate(String transactionId, State currentState, @Nullable State newState) { | ||
// nop | ||
} | ||
|
||
@Override | ||
public void outgoingResponse(String transactionId, Response response) { | ||
// nop | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Called when new request regarding given transaction is received. | ||
* | ||
* @param transactionId ID of transaction | ||
* @param request request to be processed | ||
* @param timestamp timestamp of the request | ||
* @param watermark watermark of all requests | ||
*/ | ||
void incomingRequest(String transactionId, Request request, long timestamp, long watermark); | ||
|
||
/** | ||
* Called when transaction state is about to be updated. | ||
* | ||
* @param transactionId ID of transaction | ||
* @param currentState the current state of the transaction | ||
* @param newState the state to which the transaction will be transitioned | ||
*/ | ||
void stateUpdate(String transactionId, State currentState, @Nullable State newState); | ||
|
||
/** | ||
* Called when a response to transaction client is about to be sent. | ||
* | ||
* @param transactionId ID of transaction | ||
* @param response the response to be sent | ||
*/ | ||
void outgoingResponse(String transactionId, Response response); | ||
} |
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
60 changes: 60 additions & 0 deletions
60
...-manager/src/test/java/cz/o2/proxima/direct/transaction/manager/TestMonitoringPolicy.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,60 @@ | ||
/* | ||
* Copyright 2017-2024 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.direct.transaction.manager; | ||
|
||
import cz.o2.proxima.core.transaction.Request; | ||
import cz.o2.proxima.core.transaction.Response; | ||
import cz.o2.proxima.core.transaction.State; | ||
import cz.o2.proxima.core.util.Pair; | ||
import cz.o2.proxima.direct.core.transaction.TransactionMonitoringPolicy; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
|
||
public class TestMonitoringPolicy implements TransactionMonitoringPolicy { | ||
|
||
private static List<Request> requests = Collections.synchronizedList(new ArrayList<>()); | ||
private static List<Response> responses = Collections.synchronizedList(new ArrayList<>()); | ||
private static List<Pair<State, State>> states = Collections.synchronizedList(new ArrayList<>()); | ||
|
||
public static void clear() { | ||
requests.clear(); | ||
responses.clear(); | ||
states.clear(); | ||
} | ||
|
||
public static boolean isEmpty() { | ||
return requests.isEmpty() || responses.isEmpty() || states.isEmpty(); | ||
} | ||
|
||
@Override | ||
public void incomingRequest( | ||
String transactionId, Request request, long timestamp, long watermark) { | ||
|
||
requests.add(request); | ||
} | ||
|
||
@Override | ||
public void stateUpdate(String transactionId, State currentState, @Nullable State newState) { | ||
states.add(Pair.of(currentState, newState)); | ||
} | ||
|
||
@Override | ||
public void outgoingResponse(String transactionId, Response response) { | ||
responses.add(response); | ||
} | ||
} |
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