Skip to content

Commit

Permalink
[eclipse-ditto#926] remove raw type usage in persistence actors.
Browse files Browse the repository at this point in the history
Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Dec 26, 2020
1 parent 23d261f commit e9f270f
Show file tree
Hide file tree
Showing 117 changed files with 408 additions and 398 deletions.
Expand Up @@ -116,8 +116,8 @@
* remote server is delegated to a child actor that uses a specific client (AMQP 1.0 or 0.9.1).
*/
public final class ConnectionPersistenceActor
extends AbstractShardedPersistenceActor<ConnectivityCommand, Connection, ConnectionId, ConnectionState,
ConnectivityEvent> {
extends AbstractShardedPersistenceActor<ConnectivityCommand<?>, Connection, ConnectionId, ConnectionState,
ConnectivityEvent<?>> {

/**
* Prefix to prepend to the connection ID to construct the persistence ID.
Expand Down Expand Up @@ -254,7 +254,7 @@ public String snapshotPluginId() {
}

@Override
protected Class<ConnectivityEvent> getEventClass() {
protected Class<?> getEventClass() {
return ConnectivityEvent.class;
}

Expand All @@ -274,7 +274,7 @@ protected ConnectionDeletedStrategies getDeletedStrategy() {
}

@Override
protected EventStrategy<ConnectivityEvent, Connection> getEventStrategy() {
protected EventStrategy<ConnectivityEvent<?>, Connection> getEventStrategy() {
return ConnectionEventStrategies.getInstance();
}

Expand All @@ -295,12 +295,12 @@ protected boolean entityExistsAsDeleted() {
}

@Override
protected DittoRuntimeExceptionBuilder newNotAccessibleExceptionBuilder() {
protected DittoRuntimeExceptionBuilder<?> newNotAccessibleExceptionBuilder() {
return ConnectionNotAccessibleException.newBuilder(entityId);
}

@Override
protected void publishEvent(final ConnectivityEvent event) {
protected void publishEvent(final ConnectivityEvent<?> event) {
// Do nothing because nobody subscribes for connectivity events.
}

Expand Down Expand Up @@ -341,8 +341,8 @@ protected void recoveryCompleted(final RecoveryCompleted event) {
}

@Override
public void onMutation(final Command command, final ConnectivityEvent event, final WithDittoHeaders response,
final boolean becomeCreated, final boolean becomeDeleted) {
public void onMutation(final Command<?> command, final ConnectivityEvent<?> event,
final WithDittoHeaders<?> response, final boolean becomeCreated, final boolean becomeDeleted) {
if (command instanceof StagedCommand) {
interpretStagedCommand(((StagedCommand) command).withSenderUnlessDefined(getSender()));
} else {
Expand Down Expand Up @@ -381,9 +381,7 @@ private void interpretStagedCommand(final StagedCommand command) {
interpretStagedCommand(command.next());
break;
case PERSIST_AND_APPLY_EVENT:
persistAndApplyEvent(command.getEvent(), (event, connection) -> {
interpretStagedCommand(command.next());
});
persistAndApplyEvent(command.getEvent(), (event, connection) -> interpretStagedCommand(command.next()));
break;
case SEND_RESPONSE:
command.getSender().tell(command.getResponse(), getSelf());
Expand Down
Expand Up @@ -42,18 +42,18 @@
*/
public final class StagedCommand implements ConnectivityCommand<StagedCommand>, Iterator<StagedCommand> {

private static final ConnectivityEvent DUMMY_EVENT =
private static final ConnectivityEvent<?> DUMMY_EVENT =
ConnectionClosed.of(ConnectionId.dummy(), DittoHeaders.empty());

private final ConnectivityCommand command;
private final ConnectivityEvent event;
private final WithDittoHeaders response;
private final ConnectivityCommand<?> command;
private final ConnectivityEvent<?> event;
private final WithDittoHeaders<?> response;
private final ActorRef sender;
private final Collection<ConnectionAction> actions;

private StagedCommand(final ConnectivityCommand command,
final ConnectivityEvent event,
final WithDittoHeaders response,
private StagedCommand(final ConnectivityCommand<?> command,
final ConnectivityEvent<?> event,
final WithDittoHeaders<?> response,
final ActorRef sender,
final Collection<ConnectionAction> actions) {
this.command = command;
Expand All @@ -72,36 +72,36 @@ private StagedCommand(final ConnectivityCommand command,
* @param actions remaining actions.
* @return the staged command.
*/
public static StagedCommand of(final ConnectivityCommand command, final ConnectivityEvent event,
final WithDittoHeaders response, final List<ConnectionAction> actions) {
public static StagedCommand of(final ConnectivityCommand<?> command, final ConnectivityEvent<?> event,
final WithDittoHeaders<?> response, final List<ConnectionAction> actions) {
return new StagedCommand(command, event, response, ActorRef.noSender(), actions);
}

/**
* @return a dummy placeholder event.
*/
public static ConnectivityEvent dummyEvent() {
public static ConnectivityEvent<?> dummyEvent() {
return DUMMY_EVENT;
}

/**
* @return the wrapped command.
*/
public ConnectivityCommand getCommand() {
public ConnectivityCommand<?> getCommand() {
return command;
}

/**
* @return the event to persist, apply or publish.
*/
public ConnectivityEvent getEvent() {
public ConnectivityEvent<?> getEvent() {
return event;
}

/**
* @return the response to send to the original sender, or the signal to forward to client actors.
*/
public WithDittoHeaders getResponse() {
public WithDittoHeaders<?> getResponse() {
return response;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public StagedCommand withSenderUnlessDefined(final ActorRef newSender) {
* @param response the response.
* @return the copy.
*/
public StagedCommand withResponse(final WithDittoHeaders response) {
public StagedCommand withResponse(final WithDittoHeaders<?> response) {
return new StagedCommand(command, event, response, sender, actions);
}

Expand Down
Expand Up @@ -35,8 +35,8 @@
*
* @param <C> the type of the handled command
*/
abstract class AbstractConnectivityCommandStrategy<C extends ConnectivityCommand>
extends AbstractCommandStrategy<C, Connection, ConnectionState, Result<ConnectivityEvent>> {
abstract class AbstractConnectivityCommandStrategy<C extends ConnectivityCommand<?>>
extends AbstractCommandStrategy<C, Connection, ConnectionState, Result<ConnectivityEvent<?>>> {

AbstractConnectivityCommandStrategy(final Class<C> theMatchingClass) {
super(theMatchingClass);
Expand All @@ -54,14 +54,14 @@ protected Optional<Metadata> calculateRelativeMetadata(@Nullable final Connectio
}

ConnectionNotAccessibleException notAccessible(final Context<ConnectionState> context,
final WithDittoHeaders command) {
final WithDittoHeaders<?> command) {
return ConnectionNotAccessibleException.newBuilder(context.getState().id())
.dittoHeaders(command.getDittoHeaders())
.build();
}

static Optional<DittoRuntimeException> validate(final Context<ConnectionState> context,
final ConnectivityCommand command, final Connection connection) {
final ConnectivityCommand<?> command, final Connection connection) {
try {
context.getState().getValidator().accept(command, () -> connection);
return Optional.empty();
Expand Down
Expand Up @@ -34,26 +34,27 @@
*
* @param <C> the type of the handled command
*/
abstract class AbstractEphemeralStrategy<C extends ConnectivityCommand> extends AbstractConnectivityCommandStrategy<C> {
abstract class AbstractEphemeralStrategy<C extends ConnectivityCommand<?>>
extends AbstractConnectivityCommandStrategy<C> {


AbstractEphemeralStrategy(final Class<C> theMatchingClass) {
super(theMatchingClass);
}

abstract WithDittoHeaders getResponse(final ConnectionState connectionId, final DittoHeaders headers);
abstract WithDittoHeaders<?> getResponse(final ConnectionState connectionId, final DittoHeaders headers);

abstract List<ConnectionAction> getActions();

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection connection,
final long nextRevision,
final C command,
@Nullable final Metadata metadata) {

final ConnectivityEvent event = StagedCommand.dummyEvent();
final WithDittoHeaders response = getResponse(context.getState(), command.getDittoHeaders());
final ConnectivityEvent<?> event = StagedCommand.dummyEvent();
final WithDittoHeaders<?> response = getResponse(context.getState(), command.getDittoHeaders());
final List<ConnectionAction> actions = getActions();
return newMutationResult(StagedCommand.of(command, event, response, actions), event, response);
}
Expand Down
Expand Up @@ -33,7 +33,7 @@
*
* @param <C> the type of the handled command
*/
abstract class AbstractSingleActionStrategy<C extends ConnectivityCommand>
abstract class AbstractSingleActionStrategy<C extends ConnectivityCommand<?>>
extends AbstractConnectivityCommandStrategy<C> {

AbstractSingleActionStrategy(final Class<C> theMatchingClass) {
Expand All @@ -46,13 +46,13 @@ abstract class AbstractSingleActionStrategy<C extends ConnectivityCommand>
abstract ConnectionAction getAction();

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection connection,
final long nextRevision,
final C command,
@Nullable final Metadata metadata) {

final ConnectivityEvent event = StagedCommand.dummyEvent();
final ConnectivityEvent<?> event = StagedCommand.dummyEvent();
final List<ConnectionAction> actions = Collections.singletonList(getAction());
return newMutationResult(StagedCommand.of(command, event, command, actions), event, command);
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ final class CloseConnectionStrategy extends AbstractConnectivityCommandStrategy<
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection connection,
final long nextRevision,
final CloseConnection command,
Expand Down
Expand Up @@ -35,7 +35,7 @@ final class ConnectionConflictStrategy extends AbstractConnectivityCommandStrate
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final CreateConnection command,
Expand Down
Expand Up @@ -27,7 +27,8 @@
* Strategies to handle signals as an existing connection.
*/
public class ConnectionCreatedStrategies
extends AbstractCommandStrategies<ConnectivityCommand, Connection, ConnectionState, Result<ConnectivityEvent>> {
extends
AbstractCommandStrategies<ConnectivityCommand<?>, Connection, ConnectionState, Result<ConnectivityEvent<?>>> {

private static final ConnectionCreatedStrategies CREATED_STRATEGIES = newCreatedStrategies();

Expand Down Expand Up @@ -63,16 +64,16 @@ private static ConnectionCreatedStrategies newCreatedStrategies() {
}

@Override
public boolean isDefined(final ConnectivityCommand command) {
public boolean isDefined(final ConnectivityCommand<?> command) {
// always defined so as to forward signals.
return true;
}

@Override
public Result<ConnectivityEvent> unhandled(final Context<ConnectionState> context,
public Result<ConnectivityEvent<?>> unhandled(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final ConnectivityCommand command) {
final ConnectivityCommand<?> command) {

return ResultFactory.newErrorResult(ConnectionNotAccessibleException
.newBuilder(context.getState().id())
Expand All @@ -81,7 +82,7 @@ public Result<ConnectivityEvent> unhandled(final Context<ConnectionState> contex
}

@Override
protected Result<ConnectivityEvent> getEmptyResult() {
protected Result<ConnectivityEvent<?>> getEmptyResult() {
return ResultFactory.emptyResult();
}

Expand Down
Expand Up @@ -27,7 +27,8 @@
* Strategies to handle signals as a nonexistent connection.
*/
public class ConnectionDeletedStrategies
extends AbstractCommandStrategies<ConnectivityCommand, Connection, ConnectionState, Result<ConnectivityEvent>> {
extends
AbstractCommandStrategies<ConnectivityCommand<?>, Connection, ConnectionState, Result<ConnectivityEvent<?>>> {

private static final ConnectionDeletedStrategies DELETED_STRATEGIES = newDeletedStrategies();

Expand All @@ -51,10 +52,10 @@ private static ConnectionDeletedStrategies newDeletedStrategies() {
}

@Override
public Result<ConnectivityEvent> unhandled(final Context<ConnectionState> context,
public Result<ConnectivityEvent<?>> unhandled(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final ConnectivityCommand command) {
final ConnectivityCommand<?> command) {

context.getLog().withCorrelationId(command)
.warning("Received command for deleted connection, rejecting: <{}>", command);
Expand All @@ -64,13 +65,13 @@ public Result<ConnectivityEvent> unhandled(final Context<ConnectionState> contex
}

@Override
public boolean isDefined(final ConnectivityCommand command) {
public boolean isDefined(final ConnectivityCommand<?> command) {
// always defined so as to log ignored signals on debug level.
return true;
}

@Override
protected Result<ConnectivityEvent> getEmptyResult() {
protected Result<ConnectivityEvent<?>> getEmptyResult() {
return ResultFactory.emptyResult();
}

Expand Down
Expand Up @@ -51,7 +51,7 @@ final class CreateConnectionStrategy extends AbstractConnectivityCommandStrategy
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final CreateConnection command,
Expand Down
Expand Up @@ -47,7 +47,7 @@ final class DeleteConnectionStrategy extends AbstractConnectivityCommandStrategy
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection connection,
final long nextRevision,
final DeleteConnection command,
Expand Down
Expand Up @@ -54,7 +54,7 @@ final class ModifyConnectionStrategy extends AbstractConnectivityCommandStrategy
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final ModifyConnection command,
Expand Down
Expand Up @@ -48,7 +48,7 @@ final class OpenConnectionStrategy extends AbstractConnectivityCommandStrategy<O
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection connection,
final long nextRevision,
final OpenConnection command,
Expand Down
Expand Up @@ -33,7 +33,7 @@ final class RetrieveConnectionStrategy extends AbstractConnectivityCommandStrate
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final RetrieveConnection command,
Expand Down
Expand Up @@ -33,7 +33,7 @@ final class StagedCommandStrategy extends AbstractConnectivityCommandStrategy<St
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final StagedCommand command,
Expand Down
Expand Up @@ -35,7 +35,7 @@ final class TestConnectionConflictStrategy extends AbstractConnectivityCommandSt
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final TestConnection command,
Expand Down
Expand Up @@ -48,7 +48,7 @@ final class TestConnectionStrategy extends AbstractConnectivityCommandStrategy<T
}

@Override
protected Result<ConnectivityEvent> doApply(final Context<ConnectionState> context,
protected Result<ConnectivityEvent<?>> doApply(final Context<ConnectionState> context,
@Nullable final Connection entity,
final long nextRevision,
final TestConnection command,
Expand Down

0 comments on commit e9f270f

Please sign in to comment.