-
Notifications
You must be signed in to change notification settings - Fork 214
/
ConnectionCreatedStrategies.java
94 lines (82 loc) · 4.12 KB
/
ConnectionCreatedStrategies.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2022 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.messaging.persistence.strategies.commands;
import javax.annotation.Nullable;
import org.eclipse.ditto.base.model.signals.commands.Command;
import org.eclipse.ditto.connectivity.api.commands.sudo.ConnectivitySudoCommand;
import org.eclipse.ditto.connectivity.model.Connection;
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand;
import org.eclipse.ditto.connectivity.model.signals.commands.exceptions.ConnectionNotAccessibleException;
import org.eclipse.ditto.connectivity.model.signals.events.ConnectivityEvent;
import org.eclipse.ditto.connectivity.service.messaging.persistence.stages.ConnectionState;
import org.eclipse.ditto.internal.utils.persistentactors.commands.AbstractCommandStrategies;
import org.eclipse.ditto.internal.utils.persistentactors.results.Result;
import org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory;
import org.apache.pekko.actor.ActorSystem;
/**
* Strategies to handle signals as an existing connection.
*/
public final class ConnectionCreatedStrategies
extends AbstractCommandStrategies<Command<?>, Connection, ConnectionState, ConnectivityEvent<?>>
implements ConnectivityCommandStrategies {
private ConnectionCreatedStrategies() {
super(Command.class);
}
/**
* @param actorSystem Actor system reference
* @return the unique instance of this class.
*/
public static ConnectionCreatedStrategies getInstance(final ActorSystem actorSystem) {
return newCreatedStrategies(actorSystem);
}
private static ConnectionCreatedStrategies newCreatedStrategies(final ActorSystem actorSystem) {
final ConnectionCreatedStrategies strategies = new ConnectionCreatedStrategies();
strategies.addStrategy(new StagedCommandStrategy());
strategies.addStrategy(new TestConnectionConflictStrategy());
strategies.addStrategy(new ConnectionConflictStrategy());
strategies.addStrategy(new ModifyConnectionStrategy());
strategies.addStrategy(new DeleteConnectionStrategy());
strategies.addStrategy(new OpenConnectionStrategy());
strategies.addStrategy(new CloseConnectionStrategy());
strategies.addStrategy(new ResetConnectionMetricsStrategy());
strategies.addStrategy(new EnableConnectionLogsStrategy());
strategies.addStrategy(new RetrieveConnectionLogsStrategy());
strategies.addStrategy(new ResetConnectionLogsStrategy());
strategies.addStrategy(new RetrieveConnectionStrategy());
strategies.addStrategy(new RetrieveResolvedHonoConnectionStrategy(actorSystem));
strategies.addStrategy(new RetrieveConnectionStatusStrategy());
strategies.addStrategy(new RetrieveConnectionMetricsStrategy());
strategies.addStrategy(new LoggingExpiredStrategy());
strategies.addStrategy(new SudoRetrieveConnectionTagsStrategy());
strategies.addStrategy(new SudoAddConnectionLogEntryStrategy());
return strategies;
}
@Override
public boolean isDefined(final Command<?> command) {
return command instanceof ConnectivityCommand || command instanceof ConnectivitySudoCommand;
}
@Override
public Result<ConnectivityEvent<?>> unhandled(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final Command<?> command) {
return ResultFactory.newErrorResult(ConnectionNotAccessibleException
.newBuilder(context.getState().id())
.dittoHeaders(command.getDittoHeaders())
.build(), command);
}
@Override
protected Result<ConnectivityEvent<?>> getEmptyResult() {
return ResultFactory.emptyResult();
}
}