Skip to content

Commit

Permalink
dev doc improvement #74
Browse files Browse the repository at this point in the history
  • Loading branch information
Isuru Weerarathna committed Feb 19, 2021
1 parent 669551e commit 9828db5
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 148 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/io/github/oasis/core/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
import java.io.Serializable;
import java.util.Map;

/**
* Base interface for all game events. Game events ultimately consumed by
* {@link io.github.oasis.core.elements.AbstractRule} rules.
*
* @author Isuru Weerarathna
*/
public interface Event extends Serializable {

String ID = "id";
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/io/github/oasis/core/EventJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Map;

/**
* Json based event.
*
* @author Isuru Weerarathna
*/
public class EventJson implements Event {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/io/github/oasis/core/EventScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.Objects;

/**
* Represents the scope of a event.
*
* @author Isuru Weerarathna
*/
public class EventScope implements Comparable<EventScope> {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/io/github/oasis/core/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.Serializable;

/**
* Representation of game definition.
*
* @author Isuru Weerarathna
*/
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import io.github.oasis.core.external.messages.PersistedDef;

/**
* Asynchronous event dispatch support for message brokers.
*
* For synchronous dispatch support please see {@link EventDispatchSupport}.
*
* @author Isuru Weerarathna
*/
public interface EventAsyncDispatchSupport extends EventDispatchSupport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import java.util.Map;

/**
* Base interface to implement for event dispatching to a different
* message brokers.
*
* For asynchronous dispatch support please see {@link EventAsyncDispatchSupport}.
*
* @author Isuru Weerarathna
*/
public interface EventDispatchSupport extends Closeable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import java.util.Optional;

/**
* Base interface to implement for storage of individual event data.
* This interface will be used by engine to store some of events based
* on the rule type to refer them later in execution process.
*
* @author Isuru Weerarathna
*/
public interface EventReadWrite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
package io.github.oasis.core.external;

/**
* Combined modular support of event dispatching and receiving
* for a particular message broker.
*
* Each message broker should implement one factory.
*
* @author Isuru Weerarathna
*/
public interface EventStreamFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import io.github.oasis.core.external.messages.PersistedDef;

/**
* Accepts messages for game engine.
* Accepts messages through implementations of {@link SourceStreamSupport}
* for game engine.
*
* @author Isuru Weerarathna
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.Closeable;

/**
* Base interface to implement to subscribe for game event messages.
*
* @author Isuru Weerarathna
*/
public interface SourceStreamSupport extends Closeable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@

package io.github.oasis.core.external.messages;

import lombok.Getter;
import lombok.ToString;

/**
* Acknowledgable oasis message class which can be used to requeue
* messages in case of processing failures.
*
* @author Isuru Weerarathna
*/
@Getter
@ToString
public class AckableOasisMessage implements OasisCommand {

private Object externalMessageId;
private final Object externalMessageId;

public AckableOasisMessage(Object externalMessageId) {
this.externalMessageId = externalMessageId;
}

public Object getExternalMessageId() {
return externalMessageId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,38 @@

package io.github.oasis.core.external.messages;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
* Base command class for every game related commands.
* This command is being used to signal game status changes, such as,
* START, PAUSE, REMOVE, etc.
*
* {@link GameLifecycle} to view available game statuses.
*
* @author Isuru Weerarathna
*/
@Getter
@Setter
@ToString
public class GameCommand implements OasisCommand {

private int gameId;
private Object messageId;
private GameLifecycle status;

public Object getMessageId() {
return messageId;
}

public void setMessageId(Object messageId) {
this.messageId = messageId;
}

public GameLifecycle getStatus() {
return status;
}

public void setStatus(GameLifecycle status) {
this.status = status;
}

public int getGameId() {
return gameId;
}

public void setGameId(int gameId) {
this.gameId = gameId;
}

public static GameCommand create(int gameId, GameLifecycle status) {
GameCommand cmd = new GameCommand();
cmd.setGameId(gameId);
cmd.setStatus(status);
return cmd;
}

/**
* Life cycle statuses of a game.
*/
public enum GameLifecycle {
CREATE,
START,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

package io.github.oasis.core.external.messages;

import java.io.Serializable;

/**
* Base interface for all oasis commands.
*
* @author Isuru Weerarathna
*/
public interface OasisCommand {
public interface OasisCommand extends Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package io.github.oasis.core.external.messages;

import io.github.oasis.core.Event;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;
Expand All @@ -28,6 +30,8 @@
/**
* @author Isuru Weerarathna
*/
@Getter
@Setter
public class PersistedDef implements Serializable {

public static final String FIELD_TYPE = "type";
Expand Down Expand Up @@ -76,46 +80,6 @@ public static PersistedDef fromEvent(Event event) {
return def;
}

public Object getMessageId() {
return messageId;
}

public void setMessageId(Object messageId) {
this.messageId = messageId;
}

public Scope getScope() {
return scope;
}

public String getImpl() {
return impl;
}

public String getType() {
return type;
}

public Map<String, Object> getData() {
return data;
}

public void setType(String type) {
this.type = type;
}

public void setImpl(String impl) {
this.impl = impl;
}

public void setScope(Scope scope) {
this.scope = scope;
}

public void setData(Map<String, Object> data) {
this.data = data;
}

public boolean isEvent() {
return GAME_EVENT.equals(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,25 @@
package io.github.oasis.core.external.messages;

import io.github.oasis.core.elements.AbstractRule;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
* Base command class for all rule related changes.
* See {@link RuleChangeType} for available list of rule activities.
*
* @author Isuru Weerarathna
*/
@Getter
@Setter
@ToString
public class RuleCommand implements OasisCommand {

private int gameId;
private RuleChangeType changeType;
private AbstractRule rule;

public AbstractRule getRule() {
return rule;
}

public void setRule(AbstractRule rule) {
this.rule = rule;
}

public RuleChangeType getChangeType() {
return changeType;
}

public void setChangeType(RuleChangeType changeType) {
this.changeType = changeType;
}

public int getGameId() {
return gameId;
}

public void setGameId(int gameId) {
this.gameId = gameId;
}

public enum RuleChangeType {
ADD,
UPDATE,
Expand Down
17 changes: 11 additions & 6 deletions engine/src/main/java/io/github/oasis/engine/DefinitionReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@
import io.github.oasis.engine.actors.cmds.Messages;
import io.github.oasis.engine.actors.cmds.OasisRuleMessage;

import java.util.Map;
import java.util.Optional;

/**
* @author Isuru Weerarathna
*/
class DefinitionReader {

private static final Map<String, RuleCommand.RuleChangeType> RULE_CHANGE_TYPE_MAP = Map.of(
PersistedDef.GAME_RULE_ADDED, RuleCommand.RuleChangeType.ADD,
PersistedDef.GAME_RULE_REMOVED, RuleCommand.RuleChangeType.REMOVE,
PersistedDef.GAME_RULE_UPDATED, RuleCommand.RuleChangeType.UPDATE
);

static Object derive(PersistedDef def, EngineContext context) {
if (def.isEvent()) {
return new EventMessage(new EventJson(def.getData()), null, def.getMessageId());
Expand Down Expand Up @@ -63,12 +72,8 @@ private static OasisRuleMessage readRuleMessage(PersistedDef def, EngineContext
}

private static RuleCommand.RuleChangeType toRuleChangeType(String type) {
switch (type) {
case PersistedDef.GAME_RULE_ADDED: return RuleCommand.RuleChangeType.ADD;
case PersistedDef.GAME_RULE_REMOVED: return RuleCommand.RuleChangeType.REMOVE;
case PersistedDef.GAME_RULE_UPDATED: return RuleCommand.RuleChangeType.UPDATE;
default: throw new IllegalArgumentException("Unknown rule change type! [" + type + "]");
}
return Optional.ofNullable(RULE_CHANGE_TYPE_MAP.get(type))
.orElseThrow(() -> new IllegalArgumentException("Unknown rule change type! [" + type + "]"));
}

private static GameCommand.GameLifecycle toLifecycleType(String type) {
Expand Down
Loading

0 comments on commit 9828db5

Please sign in to comment.