├── .gitignore ├── simple ├── src │ └── main │ │ ├── resources │ │ ├── application.conf │ │ └── logback.xml │ │ └── java │ │ └── org │ │ └── royrusso │ │ ├── command │ │ └── Command.java │ │ ├── event │ │ └── Event.java │ │ ├── actor │ │ └── SimpleActor.java │ │ └── app │ │ └── System.java └── pom.xml ├── event-bus ├── src │ └── main │ │ ├── resources │ │ ├── application.conf │ │ └── logback.xml │ │ └── java │ │ └── org │ │ └── royrusso │ │ ├── command │ │ └── Command.java │ │ ├── actor │ │ ├── Handler.java │ │ └── Emitter.java │ │ ├── event │ │ └── Event.java │ │ └── app │ │ └── System.java └── pom.xml ├── parent-child ├── src │ └── main │ │ ├── resources │ │ ├── application.conf │ │ └── logback.xml │ │ └── java │ │ └── org │ │ └── royrusso │ │ ├── command │ │ └── Command.java │ │ ├── actor │ │ ├── ChildActor.java │ │ └── ParentActor.java │ │ ├── event │ │ └── Event.java │ │ └── app │ │ └── System.java └── pom.xml ├── persistent-channel ├── src │ └── main │ │ ├── resources │ │ ├── application.conf │ │ └── logback.xml │ │ └── java │ │ └── org │ │ └── royrusso │ │ ├── command │ │ ├── Command.java │ │ └── ChannelReply.java │ │ ├── actor │ │ ├── Receiver.java │ │ └── BaseProcessor.java │ │ └── app │ │ └── System.java └── pom.xml ├── eventsourcing-persistence ├── src │ └── main │ │ ├── resources │ │ ├── application.conf │ │ └── logback.xml │ │ └── java │ │ └── org │ │ └── royrusso │ │ ├── event │ │ ├── EventHandler.java │ │ ├── Command.java │ │ └── Event.java │ │ ├── persistence │ │ ├── ProcessorState.java │ │ └── BaseProcessor.java │ │ └── app │ │ └── System.java └── pom.xml ├── README.md ├── pom.xml └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Akka Persistence 4 | /logs 5 | /journal 6 | /snapshots 7 | 8 | # Package Files # 9 | *.jar 10 | *.war 11 | *.ear 12 | 13 | # Intellij # 14 | *.iml 15 | .idea 16 | 17 | 18 | -------------------------------------------------------------------------------- /simple/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loggers = ["akka.event.slf4j.Slf4jLogger"] 3 | logLevel = "DEBUG" 4 | event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] 5 | log-dead-letters = 0 6 | log-dead-letters-during-shutdown = off 7 | log-config-on-start = off 8 | actor { 9 | provider = "akka.cluster.ClusterActorRefProvider" 10 | debug { 11 | autoreceive = on 12 | lifecycle = on 13 | event-stream = on 14 | } 15 | } 16 | remote { 17 | transport = "akka.remote.netty.NettyRemoteTransport" 18 | log-sent-messages = on 19 | log-received-messages = on 20 | log-remote-lifecycle-events = on 21 | netty.tcp { 22 | hostname = "127.0.0.1" 23 | port=2553 24 | } 25 | } 26 | cluster { 27 | seed-nodes = [ 28 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 29 | "akka.tcp://ClusterSystem@127.0.0.1:2552", 30 | "akka.tcp://ClusterSystem@127.0.0.1:2550" 31 | ] 32 | 33 | auto-down-unreachable-after = 15s 34 | } 35 | 36 | # extensions = ["akka.contrib.pattern.DistributedPubSubExtension"] 37 | } -------------------------------------------------------------------------------- /event-bus/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loggers = ["akka.event.slf4j.Slf4jLogger"] 3 | logLevel = "DEBUG" 4 | event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] 5 | log-dead-letters = 0 6 | log-dead-letters-during-shutdown = off 7 | log-config-on-start = off 8 | actor { 9 | provider = "akka.cluster.ClusterActorRefProvider" 10 | debug { 11 | autoreceive = on 12 | lifecycle = on 13 | event-stream = on 14 | } 15 | } 16 | remote { 17 | transport = "akka.remote.netty.NettyRemoteTransport" 18 | log-sent-messages = on 19 | log-received-messages = on 20 | log-remote-lifecycle-events = on 21 | netty.tcp { 22 | hostname = "127.0.0.1" 23 | port=2553 24 | } 25 | } 26 | cluster { 27 | seed-nodes = [ 28 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 29 | "akka.tcp://ClusterSystem@127.0.0.1:2552", 30 | "akka.tcp://ClusterSystem@127.0.0.1:2550" 31 | ] 32 | 33 | auto-down-unreachable-after = 15s 34 | } 35 | 36 | # extensions = ["akka.contrib.pattern.DistributedPubSubExtension"] 37 | } -------------------------------------------------------------------------------- /parent-child/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loggers = ["akka.event.slf4j.Slf4jLogger"] 3 | logLevel = "DEBUG" 4 | event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] 5 | log-dead-letters = 0 6 | log-dead-letters-during-shutdown = off 7 | log-config-on-start = off 8 | actor { 9 | provider = "akka.cluster.ClusterActorRefProvider" 10 | debug { 11 | autoreceive = on 12 | lifecycle = on 13 | event-stream = on 14 | } 15 | } 16 | remote { 17 | transport = "akka.remote.netty.NettyRemoteTransport" 18 | log-sent-messages = on 19 | log-received-messages = on 20 | log-remote-lifecycle-events = on 21 | netty.tcp { 22 | hostname = "127.0.0.1" 23 | port=2553 24 | } 25 | } 26 | cluster { 27 | seed-nodes = [ 28 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 29 | "akka.tcp://ClusterSystem@127.0.0.1:2552", 30 | "akka.tcp://ClusterSystem@127.0.0.1:2550" 31 | ] 32 | 33 | auto-down-unreachable-after = 15s 34 | } 35 | 36 | # extensions = ["akka.contrib.pattern.DistributedPubSubExtension"] 37 | } -------------------------------------------------------------------------------- /persistent-channel/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loggers = ["akka.event.slf4j.Slf4jLogger"] 3 | logLevel = "DEBUG" 4 | event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] 5 | log-dead-letters = 0 6 | log-dead-letters-during-shutdown = off 7 | log-config-on-start = off 8 | actor { 9 | provider = "akka.cluster.ClusterActorRefProvider" 10 | debug { 11 | autoreceive = on 12 | lifecycle = on 13 | event-stream = on 14 | } 15 | } 16 | remote { 17 | transport = "akka.remote.netty.NettyRemoteTransport" 18 | log-sent-messages = on 19 | log-received-messages = on 20 | log-remote-lifecycle-events = on 21 | netty.tcp { 22 | hostname = "127.0.0.1" 23 | port=2553 24 | } 25 | } 26 | cluster { 27 | seed-nodes = [ 28 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 29 | "akka.tcp://ClusterSystem@127.0.0.1:2552", 30 | "akka.tcp://ClusterSystem@127.0.0.1:2550" 31 | ] 32 | 33 | auto-down-unreachable-after = 15s 34 | } 35 | 36 | # extensions = ["akka.contrib.pattern.DistributedPubSubExtension"] 37 | } -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loggers = ["akka.event.slf4j.Slf4jLogger"] 3 | logLevel = "DEBUG" 4 | event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] 5 | log-dead-letters = 0 6 | log-dead-letters-during-shutdown = off 7 | log-config-on-start = off 8 | actor { 9 | provider = "akka.cluster.ClusterActorRefProvider" 10 | debug { 11 | autoreceive = on 12 | lifecycle = on 13 | event-stream = on 14 | } 15 | } 16 | remote { 17 | transport = "akka.remote.netty.NettyRemoteTransport" 18 | log-sent-messages = on 19 | log-received-messages = on 20 | log-remote-lifecycle-events = on 21 | netty.tcp { 22 | hostname = "127.0.0.1" 23 | port=2553 24 | } 25 | } 26 | cluster { 27 | seed-nodes = [ 28 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 29 | "akka.tcp://ClusterSystem@127.0.0.1:2552", 30 | "akka.tcp://ClusterSystem@127.0.0.1:2550" 31 | ] 32 | 33 | auto-down-unreachable-after = 15s 34 | } 35 | 36 | # extensions = ["akka.contrib.pattern.DistributedPubSubExtension"] 37 | } -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/java/org/royrusso/event/EventHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.event; 22 | 23 | import akka.actor.UntypedActor; 24 | import akka.event.Logging; 25 | import akka.event.LoggingAdapter; 26 | 27 | /** 28 | * @author royrusso 29 | */ 30 | public class EventHandler extends UntypedActor { 31 | 32 | 33 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 34 | 35 | @Override 36 | public void onReceive(Object msg) throws Exception { 37 | 38 | log.info("Handled Event: " + msg); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /simple/src/main/java/org/royrusso/command/Command.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.command; 19 | 20 | import java.io.Serializable; 21 | 22 | public class Command implements Serializable { 23 | 24 | private final String data; 25 | 26 | public Command(String data) { 27 | this.data = data; 28 | } 29 | 30 | public String getData() { 31 | return this.data; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Command{" + 37 | "data='" + data + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /event-bus/src/main/java/org/royrusso/command/Command.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.command; 19 | 20 | import java.io.Serializable; 21 | 22 | public class Command implements Serializable { 23 | 24 | private final String data; 25 | 26 | public Command(String data) { 27 | this.data = data; 28 | } 29 | 30 | public String getData() { 31 | return this.data; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Command{" + 37 | "data='" + data + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /parent-child/src/main/java/org/royrusso/command/Command.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.command; 19 | 20 | import java.io.Serializable; 21 | 22 | public class Command implements Serializable { 23 | 24 | private final String data; 25 | 26 | public Command(String data) { 27 | this.data = data; 28 | } 29 | 30 | public String getData() { 31 | return this.data; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Command{" + 37 | "data='" + data + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /persistent-channel/src/main/java/org/royrusso/command/Command.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.command; 19 | 20 | import java.io.Serializable; 21 | 22 | public class Command implements Serializable { 23 | 24 | private final String data; 25 | 26 | public Command(String data) { 27 | this.data = data; 28 | } 29 | 30 | public String getData() { 31 | return this.data; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Command{" + 37 | "data='" + data + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/java/org/royrusso/event/Command.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.event; 19 | 20 | import java.io.Serializable; 21 | 22 | public class Command implements Serializable { 23 | 24 | private final String data; 25 | 26 | public Command(String data) { 27 | this.data = data; 28 | } 29 | 30 | public String getData() { 31 | return this.data; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Command{" + 37 | "data='" + data + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /event-bus/src/main/java/org/royrusso/actor/Handler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.actor; 22 | 23 | import akka.actor.UntypedActor; 24 | import akka.event.Logging; 25 | import akka.event.LoggingAdapter; 26 | 27 | /** 28 | * Handler processes events that were emmitted on the eventstream. 29 | * 30 | * @author royrusso 31 | */ 32 | public class Handler extends UntypedActor { 33 | 34 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 35 | 36 | @Override 37 | public void onReceive(Object msg) throws Exception { 38 | 39 | log.info("Handled Event: " + msg); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /event-bus/src/main/java/org/royrusso/event/Event.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.event; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * @author royrusso@gmail.com 27 | */ 28 | public class Event implements Serializable { 29 | 30 | private final String data; 31 | 32 | public Event(String data) { 33 | this.data = data; 34 | } 35 | 36 | public String getData() { 37 | return data; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "Event{" + 43 | "data='" + data + '\'' + 44 | '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /parent-child/src/main/java/org/royrusso/actor/ChildActor.java: -------------------------------------------------------------------------------- 1 | package org.royrusso.actor; 2 | 3 | /** 4 | * 5 | * (C) Copyright 2014 Roy Russo 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | *     http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | import akka.actor.UntypedActor; 22 | import akka.event.Logging; 23 | import akka.event.LoggingAdapter; 24 | 25 | 26 | /** 27 | * Child Actor receives an Event from its Parent and logs out the message. 28 | */ 29 | public class ChildActor extends UntypedActor { 30 | 31 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 32 | 33 | @Override 34 | public void preStart() { 35 | log.info("Starting"); 36 | } 37 | 38 | @Override 39 | public void onReceive(Object msg) { 40 | log.info("Received Event: " + msg); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /simple/src/main/java/org/royrusso/event/Event.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.event; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * @author royrusso@gmail.com 27 | */ 28 | public class Event implements Serializable { 29 | 30 | private final String data; 31 | private final String uuid; 32 | 33 | public Event(String data, String uuid) { 34 | this.data = data; 35 | this.uuid = uuid; 36 | } 37 | 38 | public String getData() { 39 | return data; 40 | } 41 | 42 | public String getUuid() { 43 | return uuid; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "Event{" + 49 | "data='" + data + '\'' + 50 | ", uuid='" + uuid + '\'' + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /parent-child/src/main/java/org/royrusso/event/Event.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.event; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * @author royrusso@gmail.com 27 | */ 28 | public class Event implements Serializable { 29 | 30 | private final String data; 31 | private final String uuid; 32 | 33 | public Event(String data, String uuid) { 34 | this.data = data; 35 | this.uuid = uuid; 36 | } 37 | 38 | public String getData() { 39 | return data; 40 | } 41 | 42 | public String getUuid() { 43 | return uuid; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "Event{" + 49 | "data='" + data + '\'' + 50 | ", uuid='" + uuid + '\'' + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/java/org/royrusso/event/Event.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.event; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * @author royrusso@gmail.com 27 | */ 28 | public class Event implements Serializable { 29 | 30 | private final String data; 31 | private final String uuid; 32 | 33 | public Event(String data, String uuid) { 34 | this.data = data; 35 | this.uuid = uuid; 36 | } 37 | 38 | public String getData() { 39 | return data; 40 | } 41 | 42 | public String getUuid() { 43 | return uuid; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "Event{" + 49 | "data='" + data + '\'' + 50 | ", uuid='" + uuid + '\'' + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /persistent-channel/src/main/java/org/royrusso/command/ChannelReply.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.command; 22 | 23 | /** 24 | * @author royrusso 25 | */ 26 | public class ChannelReply { 27 | 28 | 29 | private Command command; 30 | private long sequenceNbr; 31 | 32 | public ChannelReply(Command command, long sequenceNbr) { 33 | this.command = command; 34 | this.sequenceNbr = sequenceNbr; 35 | } 36 | 37 | public Command getCommand() { 38 | return command; 39 | } 40 | 41 | public long getSequenceNbr() { 42 | return sequenceNbr; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "ChannelReply{" + 48 | "command=" + command + 49 | ", sequenceNbr=" + sequenceNbr + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/java/org/royrusso/persistence/ProcessorState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.persistence; 22 | 23 | import org.royrusso.event.Event; 24 | 25 | import java.io.Serializable; 26 | import java.util.ArrayList; 27 | 28 | /** 29 | * @author royrusso@gmail.com 30 | */ 31 | public class ProcessorState implements Serializable { 32 | private final ArrayList events; 33 | 34 | public ProcessorState() { 35 | this(new ArrayList()); 36 | } 37 | 38 | public ProcessorState(ArrayList events) { 39 | this.events = events; 40 | } 41 | 42 | public ProcessorState copy() { 43 | return new ProcessorState(new ArrayList(events)); 44 | } 45 | 46 | public void update(Event event) { 47 | events.add(event.toString()); 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return events.toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /event-bus/src/main/java/org/royrusso/actor/Emitter.java: -------------------------------------------------------------------------------- 1 | package org.royrusso.actor; 2 | 3 | /** 4 | * 5 | * (C) Copyright 2014 Roy Russo 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | *     http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | import akka.actor.UntypedActor; 22 | import akka.event.Logging; 23 | import akka.event.LoggingAdapter; 24 | import org.royrusso.command.Command; 25 | import org.royrusso.event.Event; 26 | 27 | 28 | /** 29 | * The Emitter receives a Command and emits Events that are picked up by subscribed Handler. The Handler is listening for emitted Event.class 30 | */ 31 | public class Emitter extends UntypedActor { 32 | 33 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 34 | 35 | @Override 36 | public void onReceive(Object msg) { 37 | 38 | if (msg instanceof Command) { 39 | 40 | log.info("Emitting Event: " + msg); // never seems to print to log. wtf? 41 | 42 | String data = ((Command) msg).getData(); 43 | 44 | getContext().system().eventStream().publish(new Event(data)); 45 | } 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /simple/src/main/java/org/royrusso/actor/SimpleActor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.actor; 22 | 23 | import akka.actor.UntypedActor; 24 | import akka.event.Logging; 25 | import akka.event.LoggingAdapter; 26 | import org.royrusso.command.Command; 27 | import org.royrusso.event.Event; 28 | 29 | import java.util.UUID; 30 | 31 | /** 32 | * SimpleActor receives an instance of Command and emits an Event. 33 | * 34 | * @author royrusso 35 | */ 36 | public class SimpleActor extends UntypedActor { 37 | 38 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 39 | 40 | 41 | public SimpleActor() { 42 | log.info("SimpleActor constructor"); 43 | } 44 | 45 | @Override 46 | public void onReceive(Object msg) throws Exception { 47 | 48 | log.info("Received Command: " + msg); 49 | 50 | if (msg instanceof Command) { 51 | final String data = ((Command) msg).getData(); 52 | final Event event = new Event(data, UUID.randomUUID().toString()); 53 | 54 | // emmit an event somewhere... 55 | 56 | } else if (msg.equals("echo")) { 57 | log.info("ECHO!"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /simple/src/main/java/org/royrusso/app/System.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.app; 19 | 20 | import akka.actor.ActorRef; 21 | import akka.actor.ActorSystem; 22 | import akka.actor.Props; 23 | import org.royrusso.actor.SimpleActor; 24 | import org.royrusso.command.Command; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | /** 29 | * Main runtime class. 30 | */ 31 | public class System { 32 | 33 | public static final Logger log = LoggerFactory.getLogger(System.class); 34 | 35 | public static void main(String... args) throws Exception { 36 | 37 | final ActorSystem actorSystem = ActorSystem.create("actor-system"); 38 | 39 | Thread.sleep(5000); 40 | 41 | final ActorRef actorRef = actorSystem.actorOf(Props.create(SimpleActor.class), "simple-actor"); 42 | 43 | actorRef.tell(new Command("CMD 1"), null); 44 | actorRef.tell(new Command("CMD 2"), null); 45 | actorRef.tell(new Command("CMD 3"), null); 46 | actorRef.tell(new Command("CMD 4"), null); 47 | actorRef.tell(new Command("CMD 5"), null); 48 | 49 | Thread.sleep(5000); 50 | 51 | log.debug("Actor System Shutdown Starting..."); 52 | 53 | actorSystem.shutdown(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /persistent-channel/src/main/java/org/royrusso/actor/Receiver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.actor; 22 | 23 | import akka.actor.UntypedActor; 24 | import akka.event.Logging; 25 | import akka.event.LoggingAdapter; 26 | import akka.persistence.ConfirmablePersistent; 27 | import org.royrusso.command.ChannelReply; 28 | import org.royrusso.command.Command; 29 | 30 | /** 31 | * Receives commands that are sent via the listened-to channel and then replies with a sort of echo statement. 32 | * 33 | * @author royrusso 34 | */ 35 | public class Receiver extends UntypedActor { 36 | 37 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 38 | 39 | @Override 40 | public void onReceive(Object msg) throws Exception { 41 | 42 | if (msg instanceof ConfirmablePersistent) { 43 | 44 | ConfirmablePersistent confirmablePersistent = (ConfirmablePersistent) msg; 45 | 46 | log.info("Incoming Paylod: " + confirmablePersistent.payload() + " #: " + confirmablePersistent.sequenceNr()); 47 | 48 | getSender().tell(new ChannelReply((Command) confirmablePersistent.payload(), confirmablePersistent.sequenceNr()), null); 49 | confirmablePersistent.confirm(); 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /parent-child/src/main/java/org/royrusso/app/System.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.app; 19 | 20 | import akka.actor.ActorRef; 21 | import akka.actor.ActorSystem; 22 | import akka.actor.Props; 23 | import org.royrusso.actor.ParentActor; 24 | import org.royrusso.command.Command; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | /** 29 | * Main runtime class. 30 | */ 31 | public class System { 32 | 33 | public static final Logger log = LoggerFactory.getLogger(System.class); 34 | 35 | public static void main(String... args) throws Exception { 36 | 37 | final ActorSystem actorSystem = ActorSystem.create("actor-system"); 38 | 39 | Thread.sleep(5000); 40 | 41 | final ActorRef actorRef = actorSystem.actorOf(Props.create(ParentActor.class), "parent-actor"); 42 | 43 | actorRef.tell(new Command("CMD 1"), null); 44 | actorRef.tell(new Command("CMD 2"), null); 45 | actorRef.tell(new Command("CMD 3"), null); 46 | actorRef.tell("echo", null); 47 | actorRef.tell(new Command("CMD 4"), null); 48 | actorRef.tell(new Command("CMD 5"), null); 49 | 50 | Thread.sleep(5000); 51 | 52 | log.debug("Actor System Shutdown Starting..."); 53 | 54 | actorSystem.shutdown(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /persistent-channel/src/main/java/org/royrusso/app/System.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.app; 19 | 20 | import akka.actor.ActorRef; 21 | import akka.actor.ActorSystem; 22 | import akka.actor.Props; 23 | import akka.persistence.Persistent; 24 | import org.royrusso.actor.BaseProcessor; 25 | import org.royrusso.actor.Receiver; 26 | import org.royrusso.command.Command; 27 | import org.slf4j.Logger; 28 | import org.slf4j.LoggerFactory; 29 | 30 | /** 31 | * Main runtime class. 32 | */ 33 | public class System { 34 | 35 | public static final Logger log = LoggerFactory.getLogger(System.class); 36 | 37 | public static void main(String... args) throws Exception { 38 | 39 | final ActorSystem actorSystem = ActorSystem.create("channel-system"); 40 | 41 | Thread.sleep(2000); 42 | 43 | final ActorRef receiver = actorSystem.actorOf(Props.create(Receiver.class)); 44 | final ActorRef processor = actorSystem.actorOf(Props.create(BaseProcessor.class, receiver), "channel-processor"); 45 | 46 | 47 | for (int i = 0; i < 10; i++) { 48 | processor.tell(Persistent.create(new Command("CMD " + i)), null); 49 | } 50 | 51 | Thread.sleep(2000); 52 | 53 | log.debug("Actor System Shutdown Starting..."); 54 | 55 | actorSystem.shutdown(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /parent-child/src/main/java/org/royrusso/actor/ParentActor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | 21 | package org.royrusso.actor; 22 | 23 | import akka.actor.ActorRef; 24 | import akka.actor.Props; 25 | import akka.actor.UntypedActor; 26 | import akka.event.Logging; 27 | import akka.event.LoggingAdapter; 28 | import org.royrusso.command.Command; 29 | import org.royrusso.event.Event; 30 | 31 | import java.util.UUID; 32 | 33 | /** 34 | * ParentActor receives an instance of Command and emits an Event to the ChildActor. 35 | * 36 | * @author royrusso 37 | */ 38 | public class ParentActor extends UntypedActor { 39 | 40 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 41 | 42 | private final ActorRef childActor; 43 | 44 | public ParentActor() { 45 | childActor = getContext().actorOf(Props.create(ChildActor.class), "child-actor"); 46 | } 47 | 48 | @Override 49 | public void onReceive(Object msg) throws Exception { 50 | 51 | log.info("Received Command: " + msg); 52 | 53 | if (msg instanceof Command) { 54 | final String data = ((Command) msg).getData(); 55 | final Event event = new Event(data, UUID.randomUUID().toString()); 56 | 57 | childActor.tell(event, getSelf()); 58 | } else if (msg.equals("echo")) { 59 | log.info("ECHO!"); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /event-bus/src/main/java/org/royrusso/app/System.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.app; 19 | 20 | import akka.actor.ActorRef; 21 | import akka.actor.ActorSystem; 22 | import akka.actor.Props; 23 | import org.royrusso.actor.Emitter; 24 | import org.royrusso.actor.Handler; 25 | import org.royrusso.command.Command; 26 | import org.royrusso.event.Event; 27 | import org.slf4j.Logger; 28 | import org.slf4j.LoggerFactory; 29 | 30 | /** 31 | * Main runtime class. 32 | *

33 | * Create the Emitter Actor that will handle the initial Commands. The Emitter will publish events, of type Event, on the Akka EventBus. 34 | * We configure a Handler that will listen for instances of Event on the event stream. 35 | */ 36 | public class System { 37 | 38 | public static final Logger log = LoggerFactory.getLogger(System.class); 39 | 40 | public static void main(String... args) throws Exception { 41 | 42 | final ActorSystem actorSystem = ActorSystem.create("event-system"); 43 | 44 | Thread.sleep(5000); 45 | 46 | final ActorRef emitter = actorSystem.actorOf(Props.create(Emitter.class)); 47 | final ActorRef handler = actorSystem.actorOf(Props.create(Handler.class)); 48 | actorSystem.eventStream().subscribe(handler, Event.class); 49 | 50 | 51 | for (int i = 0; i < 10; i++) { 52 | emitter.tell(new Command("CMD " + i), null); 53 | } 54 | 55 | Thread.sleep(5000); 56 | 57 | log.debug("Actor System Shutdown Starting..."); 58 | 59 | actorSystem.shutdown(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/java/org/royrusso/app/System.java: -------------------------------------------------------------------------------- 1 | /** 2 |  * (C) Copyright 2014 Roy Russo 3 |  * 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); 5 |  * you may not use this file except in compliance with the License. 6 |  * You may obtain a copy of the License at 7 |  * 8 |  *     http://www.apache.org/licenses/LICENSE-2.0 9 |  * 10 |  * Unless required by applicable law or agreed to in writing, software 11 |  * distributed under the License is distributed on an "AS IS" BASIS, 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 |  * See the License for the specific language governing permissions and 14 |  * limitations under the License. 15 |  * 16 |  */ 17 | 18 | package org.royrusso.app; 19 | 20 | import akka.actor.ActorRef; 21 | import akka.actor.ActorSystem; 22 | import akka.actor.Props; 23 | import org.royrusso.event.Command; 24 | import org.royrusso.event.Event; 25 | import org.royrusso.event.EventHandler; 26 | import org.royrusso.persistence.BaseProcessor; 27 | import org.slf4j.Logger; 28 | import org.slf4j.LoggerFactory; 29 | 30 | public class System { 31 | 32 | 33 | public static final Logger log = LoggerFactory.getLogger(System.class); 34 | 35 | public static void main(String... args) throws Exception { 36 | 37 | final ActorSystem actorSystem = ActorSystem.create("actor-server"); 38 | 39 | final ActorRef handler = actorSystem.actorOf(Props.create(EventHandler.class)); 40 | actorSystem.eventStream().subscribe(handler, Event.class); 41 | 42 | Thread.sleep(5000); 43 | 44 | final ActorRef actorRef = actorSystem.actorOf(Props.create(BaseProcessor.class), "eventsourcing-processor"); 45 | 46 | actorRef.tell(new Command("CMD 1"), null); 47 | actorRef.tell(new Command("CMD 2"), null); 48 | actorRef.tell(new Command("CMD 3"), null); 49 | actorRef.tell("snapshot", null); 50 | actorRef.tell(new Command("CMD 4"), null); 51 | actorRef.tell(new Command("CMD 5"), null); 52 | actorRef.tell("printstate", null); 53 | 54 | Thread.sleep(5000); 55 | 56 | log.debug("Actor System Shutdown Starting..."); 57 | 58 | actorSystem.shutdown(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /simple/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | logs/%d{yyyy-MM-dd}.%i.log 15 | 17 | 18 | 64 MB 19 | 20 | 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | %date{ISO8601} %-5level %logger{36} %X{sourceThread} %X{akkaSource} - %msg%n 33 | 34 | 35 | 36 | DEBUG 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | -------------------------------------------------------------------------------- /event-bus/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | logs/%d{yyyy-MM-dd}.%i.log 15 | 17 | 18 | 64 MB 19 | 20 | 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | %date{ISO8601} %-5level %logger{36} %X{sourceThread} %X{akkaSource} - %msg%n 33 | 34 | 35 | 36 | DEBUG 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | -------------------------------------------------------------------------------- /parent-child/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | logs/%d{yyyy-MM-dd}.%i.log 15 | 17 | 18 | 64 MB 19 | 20 | 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | %date{ISO8601} %-5level %logger{36} %X{sourceThread} %X{akkaSource} - %msg%n 33 | 34 | 35 | 36 | DEBUG 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | -------------------------------------------------------------------------------- /persistent-channel/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | logs/%d{yyyy-MM-dd}.%i.log 15 | 17 | 18 | 64 MB 19 | 20 | 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | %date{ISO8601} %-5level %logger{36} %X{sourceThread} %X{akkaSource} - %msg%n 33 | 34 | 35 | 36 | DEBUG 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | logs/%d{yyyy-MM-dd}.%i.log 15 | 17 | 18 | 64 MB 19 | 20 | 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | %date{ISO8601} %-5level %logger{36} %X{sourceThread} %X{akkaSource} - %msg%n 33 | 34 | 35 | 36 | DEBUG 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Akka examples in Java 2 | ============== 3 | 4 | A few examples using Akka with Java. These examples have basic structures in common: 5 | 6 | * Coded in Java. 7 | * Clustered Akka setup. 8 | * Logback / SL4J Logger. Log file is under the root path: ``/logs`` 9 | * Akka configuration has most logging options turned on. (chatty) 10 | 11 | All examples are runnable from within your IDE, by executing the ``Main`` method in the corresponding ``org.royrusso.app.System`` class. 12 | 13 | Simple Akka Example 14 | ------------------ 15 | 16 | ``/simple`` :: The simplest of Akka examples. Creates an Actor that processes a command. 17 | 18 | Akka Parent-Child Actors 19 | ------------------ 20 | 21 | ``/parent-child`` :: This example illustrates how you can configure an Akka cluster for hierarchical Actor relationships. 22 | This cluster contains Parent Actors that, given a Command, send an Event to a Child Actor for processing. 23 | 24 | Akka Persistence with EventSourcing 25 | ------------------ 26 | 27 | ``/eventsourcing-persistence`` :: Usage of the new Akka Persistence module with Event Sourcing. An Akka Processor is responsible for processing non-persistent Commands 28 | that generate Events. The Events are persisted, and then allowed to modify the state of the processor. Additionally, the events are broadcast over the eventstream. 29 | 30 | During recovery, the system then loads the persisted Events and replays them to the processor. 31 | 32 | On restart, the system will load its last known state from the latest Snapshot (``snapshot`` dir), and replay all Journaled (``journal`` dir) Events after that point. 33 | 34 | Notes: 35 | 36 | * LevelDB is used for persistence in this example. 37 | * ``/snapshots`` contains the snapshot of the processor states. 38 | * ``/journal`` contains the running journal of events. 39 | 40 | Akka Persistent Channels 41 | ----------------------- 42 | 43 | ``persistent-channel`` :: Illustrates how to send/receive payloads between actors listening on a channel. Messages are persisted until there is a valid confirmation 44 | of it being received by the destination Actor, and then deleted. This example also illustrates how the destination Actor may respond with an ack. 45 | 46 | 47 | Akka Event-Bus 48 | ------------------ 49 | 50 | ``/event-bus`` :: Here we show how the Akka EventStream can be used by Actors that are subscribed to listen for certain event types that are emitted by another actor. 51 | -------------------------------------------------------------------------------- /persistent-channel/src/main/java/org/royrusso/actor/BaseProcessor.java: -------------------------------------------------------------------------------- 1 | package org.royrusso.actor; 2 | 3 | /** 4 | * 5 | * (C) Copyright 2014 Roy Russo 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | *     http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | import akka.actor.ActorRef; 22 | import akka.actor.UntypedActor; 23 | import akka.event.Logging; 24 | import akka.event.LoggingAdapter; 25 | import akka.persistence.Deliver; 26 | import akka.persistence.Persistent; 27 | import akka.persistence.PersistentChannel; 28 | import akka.persistence.PersistentChannelSettings; 29 | import org.royrusso.command.ChannelReply; 30 | import scala.concurrent.duration.Duration; 31 | 32 | import java.util.concurrent.TimeUnit; 33 | 34 | 35 | /** 36 | * The BaseProcessor receives a Command and forwards that Command on to a channel. 37 | * Once the command is picked up by the Received on the channel, the ChannelReply is printed. 38 | */ 39 | public class BaseProcessor extends UntypedActor { 40 | 41 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 42 | 43 | private ActorRef receiver; 44 | private ActorRef channel; 45 | 46 | public BaseProcessor(ActorRef receiver) { 47 | this.receiver = receiver; 48 | this.channel = getContext().actorOf(PersistentChannel.props( 49 | PersistentChannelSettings.create() 50 | .withRedeliverInterval(Duration.create(30, TimeUnit.SECONDS)) 51 | .withPendingConfirmationsMax(10000) // max # of pending confirmations. suspend delivery until < 52 | .withPendingConfirmationsMin(2000) // min # of pending confirmation. suspend delivery until > 53 | .withReplyPersistent(true) // ack 54 | .withRedeliverMax(15)), "channel"); 55 | } 56 | 57 | @Override 58 | public void onReceive(Object msg) { 59 | 60 | if (msg instanceof Persistent) { 61 | 62 | log.info("Send to Channel: " + ((Persistent) msg).payload()); 63 | 64 | channel.tell(Deliver.create(((Persistent) msg).withPayload(((Persistent) msg).payload()), receiver.path()), getSelf()); 65 | } else if (msg instanceof ChannelReply) { 66 | log.info(msg.toString()); 67 | } 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /event-bus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | akka-java-examples 7 | org.royrusso 8 | 0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | event-bus 13 | 0.1-SNAPSHOT 14 | pom 15 | 16 | 17 | UTF-8 18 | 1.7 19 | 2.10.3 20 | 2.3.1 21 | 4.0.2.RELEASE 22 | 23 | 24 | 25 | 26 | com.typesafe.akka 27 | akka-actor_2.10 28 | ${akka.version} 29 | 30 | 31 | com.typesafe.akka 32 | akka-persistence-experimental_2.10 33 | ${akka.version} 34 | 35 | 36 | com.typesafe.akka 37 | akka-cluster_2.10 38 | ${akka.version} 39 | 40 | 41 | com.typesafe.akka 42 | akka-slf4j_2.10 43 | ${akka.version} 44 | 45 | 46 | 47 | org.scala-lang 48 | scala-library 49 | ${scala.version} 50 | 51 | 52 | 53 | ch.qos.logback 54 | logback-classic 55 | 1.1.1 56 | 57 | 58 | 59 | 60 | 61 | akka-event-bus 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-compiler-plugin 66 | 2.3.2 67 | 68 | ${jdk.version} 69 | ${jdk.version} 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /eventsourcing-persistence/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | akka-java-examples 7 | org.royrusso 8 | 0.1-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | org.royrusso 14 | eventsourcing-persistence 15 | 0.1-SNAPSHOT 16 | pom 17 | 18 | 19 | UTF-8 20 | 1.7 21 | 2.10.3 22 | 2.3.1 23 | 24 | 25 | 26 | 27 | com.typesafe.akka 28 | akka-actor_2.10 29 | ${akka.version} 30 | 31 | 32 | com.typesafe.akka 33 | akka-persistence-experimental_2.10 34 | ${akka.version} 35 | 36 | 37 | com.typesafe.akka 38 | akka-cluster_2.10 39 | ${akka.version} 40 | 41 | 42 | com.typesafe.akka 43 | akka-slf4j_2.10 44 | ${akka.version} 45 | 46 | 47 | 48 | org.scala-lang 49 | scala-library 50 | ${scala.version} 51 | 52 | 53 | 54 | ch.qos.logback 55 | logback-classic 56 | 1.1.1 57 | 58 | 59 | 60 | 61 | 62 | akka-eventsourcing 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-compiler-plugin 67 | 2.3.2 68 | 69 | ${jdk.version} 70 | ${jdk.version} 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /persistent-channel/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | akka-java-examples 7 | org.royrusso 8 | 0.1-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | persistent-channel 14 | 0.1-SNAPSHOT 15 | pom 16 | 17 | 18 | UTF-8 19 | 1.7 20 | 2.10.3 21 | 2.3.1 22 | 4.0.2.RELEASE 23 | 24 | 25 | 26 | 27 | com.typesafe.akka 28 | akka-actor_2.10 29 | ${akka.version} 30 | 31 | 32 | com.typesafe.akka 33 | akka-persistence-experimental_2.10 34 | ${akka.version} 35 | 36 | 37 | com.typesafe.akka 38 | akka-cluster_2.10 39 | ${akka.version} 40 | 41 | 42 | com.typesafe.akka 43 | akka-slf4j_2.10 44 | ${akka.version} 45 | 46 | 47 | 48 | org.scala-lang 49 | scala-library 50 | ${scala.version} 51 | 52 | 53 | 54 | ch.qos.logback 55 | logback-classic 56 | 1.1.1 57 | 58 | 59 | 60 | 61 | 62 | akka-persistent-channel 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-compiler-plugin 67 | 2.3.2 68 | 69 | ${jdk.version} 70 | ${jdk.version} 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /simple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | akka-java-examples 7 | org.royrusso 8 | 0.1-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | org.royrusso 14 | akka-simple 15 | 0.1-SNAPSHOT 16 | pom 17 | 18 | 19 | UTF-8 20 | 1.7 21 | 2.10.3 22 | 2.3.1 23 | 4.0.2.RELEASE 24 | 25 | 26 | 27 | 28 | com.typesafe.akka 29 | akka-actor_2.10 30 | ${akka.version} 31 | 32 | 33 | com.typesafe.akka 34 | akka-persistence-experimental_2.10 35 | ${akka.version} 36 | 37 | 38 | com.typesafe.akka 39 | akka-cluster_2.10 40 | ${akka.version} 41 | 42 | 43 | com.typesafe.akka 44 | akka-slf4j_2.10 45 | ${akka.version} 46 | 47 | 48 | 49 | org.scala-lang 50 | scala-library 51 | ${scala.version} 52 | 53 | 54 | 55 | ch.qos.logback 56 | logback-classic 57 | 1.1.1 58 | 59 | 60 | 61 | 62 | 63 | akka-simple 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-compiler-plugin 68 | 2.3.2 69 | 70 | ${jdk.version} 71 | ${jdk.version} 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /parent-child/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | akka-java-examples 7 | org.royrusso 8 | 0.1-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | org.royrusso 14 | akka-parent-child 15 | 0.1-SNAPSHOT 16 | pom 17 | 18 | 19 | UTF-8 20 | 1.7 21 | 2.10.3 22 | 2.3.1 23 | 4.0.2.RELEASE 24 | 25 | 26 | 27 | 28 | com.typesafe.akka 29 | akka-actor_2.10 30 | ${akka.version} 31 | 32 | 33 | com.typesafe.akka 34 | akka-persistence-experimental_2.10 35 | ${akka.version} 36 | 37 | 38 | com.typesafe.akka 39 | akka-cluster_2.10 40 | ${akka.version} 41 | 42 | 43 | com.typesafe.akka 44 | akka-slf4j_2.10 45 | ${akka.version} 46 | 47 | 48 | 49 | org.scala-lang 50 | scala-library 51 | ${scala.version} 52 | 53 | 54 | 55 | ch.qos.logback 56 | logback-classic 57 | 1.1.1 58 | 59 | 60 | 61 | 62 | 63 | akka-parent-child 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-compiler-plugin 68 | 2.3.2 69 | 70 | ${jdk.version} 71 | ${jdk.version} 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /eventsourcing-persistence/src/main/java/org/royrusso/persistence/BaseProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) Copyright 2014 Roy Russo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | *     http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * 17 | * 18 | */ 19 | 20 | package org.royrusso.persistence; 21 | 22 | import akka.event.Logging; 23 | import akka.event.LoggingAdapter; 24 | import akka.japi.Procedure; 25 | import akka.persistence.SnapshotOffer; 26 | import akka.persistence.UntypedEventsourcedProcessor; 27 | import org.royrusso.event.Command; 28 | import org.royrusso.event.Event; 29 | 30 | import java.util.UUID; 31 | 32 | /** 33 | * Processor receives an instance of Command. Event is generated from this and persisted. On successful 34 | * persist, it updates the state of the processor. This allows a complete recovery of state in case of failure 35 | * by replaying the events that are in the journal and snapshot(s). 36 | * 37 | * @author royrusso 38 | */ 39 | public class BaseProcessor extends UntypedEventsourcedProcessor { 40 | 41 | LoggingAdapter log = Logging.getLogger(getContext().system(), this); 42 | 43 | /** 44 | * The state of the processor 45 | */ 46 | private ProcessorState processorState = new ProcessorState(); 47 | 48 | /** 49 | * Called on restart. Loads from Snapshot first, and then replays Journal Events to update state. 50 | * 51 | * @param msg 52 | */ 53 | public void onReceiveRecover(Object msg) { 54 | log.info("Received Recover: " + msg); 55 | if (msg instanceof Event) { 56 | processorState.update((Event) msg); 57 | 58 | } else if (msg instanceof SnapshotOffer) { 59 | processorState = (ProcessorState) ((SnapshotOffer) msg).snapshot(); 60 | } 61 | } 62 | 63 | /** 64 | * Called on Command dispatch 65 | * 66 | * @param msg 67 | */ 68 | public void onReceiveCommand(Object msg) { 69 | log.info("Received Command: " + msg); 70 | if (msg instanceof Command) { 71 | final String data = ((Command) msg).getData(); 72 | 73 | // generate an event we will persist after being enriched with a uuid 74 | final Event event = new Event(data, UUID.randomUUID().toString()); 75 | 76 | // persist event and THEN update the state of the processor 77 | persist(event, new Procedure() { 78 | public void apply(Event evt) throws Exception { 79 | 80 | processorState.update(evt); 81 | 82 | // broadcast event on eventstream 83 | getContext().system().eventStream().publish(evt); 84 | } 85 | }); 86 | } else if (msg.equals("snapshot")) { 87 | saveSnapshot(processorState.copy()); 88 | } else if (msg.equals("printstate")) { 89 | log.info(processorState.toString()); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | org.royrusso 9 | akka-java-examples 10 | 0.1-SNAPSHOT 11 | 12 | parent-child 13 | event-bus 14 | simple 15 | eventsourcing-persistence 16 | channel 17 | 18 | pom 19 | 20 | 21 | UTF-8 22 | 1.7 23 | 2.10.3 24 | 2.3.1 25 | 4.0.2.RELEASE 26 | 27 | 28 | 29 | 30 | 31 | com.typesafe.akka 32 | akka-actor_2.10 33 | ${akka.version} 34 | 35 | 36 | com.typesafe.akka 37 | akka-persistence-experimental_2.10 38 | ${akka.version} 39 | 40 | 41 | com.typesafe.akka 42 | akka-cluster_2.10 43 | ${akka.version} 44 | 45 | 46 | com.typesafe.akka 47 | akka-slf4j_2.10 48 | ${akka.version} 49 | 50 | 51 | 52 | 53 | org.scala-lang 54 | scala-library 55 | ${scala.version} 56 | 57 | 58 | 59 | 60 | junit 61 | junit 62 | 4.11 63 | test 64 | 65 | 66 | 67 | ch.qos.logback 68 | logback-classic 69 | 1.1.1 70 | 71 | 72 | 73 | 74 | javax.servlet 75 | javax.servlet-api 76 | 3.1.0 77 | 78 | 79 | 80 | org.springframework 81 | spring-webmvc 82 | ${spring.version} 83 | 84 | 85 | 92 | 93 | 94 | 95 | 96 | akka-java-examples 97 | 98 | 99 | org.apache.maven.plugins 100 | maven-compiler-plugin 101 | 2.3.2 102 | 103 | ${jdk.version} 104 | ${jdk.version} 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------