> extends JsonSerializable {
26 | }
27 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/Context.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo;
17 |
18 | import net.kuujo.vertigo.util.Observable;
19 | import net.kuujo.vertigo.util.serialization.JsonSerializable;
20 |
21 | /**
22 | * Immutable configuration information for Vertigo types.
23 | *
24 | * Contexts are immutable network/component/instance configurations that
25 | * are used by Vertigo to construct networks, components, and their connections.
26 | * All contexts are ultimately derived from a {@link net.kuujo.vertigo.network.NetworkConfig}
27 | * instance. Contexts are observable through Vertigo's clustering mechanisms,
28 | * allowing networks and components to monitor configurations for changes
29 | * internally and update their state at runtime.
30 | *
31 | * @author Jordan Halterman
32 | */
33 | public interface Context> extends Observable, JsonSerializable {
34 |
35 | /**
36 | * Returns the context address.
37 | *
38 | * @return The context address.
39 | */
40 | String address();
41 |
42 | /**
43 | * Returns the context URI.
44 | *
45 | * @return The context URI.
46 | */
47 | String uri();
48 |
49 | /**
50 | * Returns a formatted representation of the context.
51 | *
52 | * @param formatted Whether to format the context.
53 | * @return A formatted representation of the context.
54 | */
55 | String toString(boolean formatted);
56 |
57 | /**
58 | * Creates a copy of the context.
59 | *
60 | * @return A copy of the context and its children.
61 | */
62 | T copy();
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/VertigoException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 the original author or authors.
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 | package net.kuujo.vertigo;
17 |
18 | import org.vertx.java.core.VertxException;
19 |
20 | /**
21 | * Base Vertigo exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class VertigoException extends VertxException {
27 |
28 | public VertigoException(String message) {
29 | super(message);
30 | }
31 |
32 | public VertigoException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public VertigoException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/ClusterException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * Cluster exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class ClusterException extends VertigoException {
27 |
28 | public ClusterException(String message) {
29 | super(message);
30 | }
31 |
32 | public ClusterException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public ClusterException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/AsyncCollection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data;
17 |
18 | import org.vertx.java.core.AsyncResult;
19 | import org.vertx.java.core.Handler;
20 |
21 | /**
22 | * Asynchronous collection.
23 | *
24 | * @author Jordan Halterman
25 | *
26 | * @param The collection data type.
27 | */
28 | public interface AsyncCollection {
29 |
30 | /**
31 | * Returns the collection name.
32 | *
33 | * @return The collection name.
34 | */
35 | String name();
36 |
37 | /**
38 | * Adds a value to the collection.
39 | *
40 | * @param value The value to add.
41 | */
42 | void add(T value);
43 |
44 | /**
45 | * Adds a value to the collection.
46 | *
47 | * @param value The value to add.
48 | * @param doneHandler An asynchronous handler to be called once complete.
49 | */
50 | void add(T value, Handler> doneHandler);
51 |
52 | /**
53 | * Removes a value from the collection.
54 | *
55 | * @param value The value to remove.
56 | */
57 | void remove(T value);
58 |
59 | /**
60 | * Removes a value from the collection.
61 | *
62 | * @param value The value to remove.
63 | * @param doneHandler An asynchronous handler to be called once complete.
64 | */
65 | void remove(T value, Handler> doneHandler);
66 |
67 | /**
68 | * Checks whether the collection contains a value.
69 | *
70 | * @param value The value to check.
71 | * @param resultHandler An asynchronous handler to be called with the result indicating
72 | * whether the collection contains the given value.
73 | */
74 | void contains(Object value, Handler> resultHandler);
75 |
76 | /**
77 | * Gets the current collection size.
78 | *
79 | * @param resultHandler An asynchronous handler to be called with the collection size.
80 | */
81 | void size(Handler> resultHandler);
82 |
83 | /**
84 | * Checks whether the collection is empty.
85 | *
86 | * @param resultHandler An asynchronous handler to be called with the result indicating
87 | * whether the collection is empty.
88 | */
89 | void isEmpty(Handler> resultHandler);
90 |
91 | /**
92 | * Clears all values from the collection.
93 | */
94 | void clear();
95 |
96 | /**
97 | * Clears all values from the collection.
98 | *
99 | * @param doneHandler An asynchronous handler to be called once the collection has been cleared.
100 | */
101 | void clear(Handler> doneHandler);
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/AsyncCounter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data;
17 |
18 | import org.vertx.java.core.AsyncResult;
19 | import org.vertx.java.core.Handler;
20 |
21 | /**
22 | * Asynchronous cluster-wide counter.
23 | *
24 | * @author Jordan Halterman
25 | */
26 | public interface AsyncCounter {
27 |
28 | /**
29 | * Returns the counter name.
30 | *
31 | * @return The counter name.
32 | */
33 | String name();
34 |
35 | /**
36 | * Gets the current counter value.
37 | *
38 | * @param doneHandler The current counter value.
39 | */
40 | void get(Handler> doneHandler);
41 |
42 | /**
43 | * Increments the counter value.
44 | */
45 | void increment();
46 |
47 | /**
48 | * Increments the counter value.
49 | *
50 | * @param doneHandler An asynchronous handler to be called once complete.
51 | */
52 | void increment(Handler> doneHandler);
53 |
54 | /**
55 | * Increments the counter and gets the new value.
56 | *
57 | * @param doneHandler An asynchronous handler to be called with the result.
58 | */
59 | void incrementAndGet(Handler> doneHandler);
60 |
61 | /**
62 | * Decrements the counter value.
63 | */
64 | void decrement();
65 |
66 | /**
67 | * Decrements the counter value.
68 | *
69 | * @param doneHandler An asynchronous handler to be called once complete.
70 | */
71 | void decrement(Handler> doneHandler);
72 |
73 | /**
74 | * Decrements the counter and gets the new value.
75 | *
76 | * @param doneHandler An asynchronous handler to be called with the result.
77 | */
78 | void decrementAndGet(Handler> doneHandler);
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/AsyncList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data;
17 |
18 | import org.vertx.java.core.AsyncResult;
19 | import org.vertx.java.core.Handler;
20 |
21 | /**
22 | * Asynchronous list.
23 | *
24 | * If the current Vert.x instance is a Hazelcast clustered instance,
25 | * the list will be backed by a Hazelcast list. Otherwise, the list
26 | * will be backed by a Vert.x shared data map.
27 | *
28 | * @author Jordan Halterman
29 | *
30 | * @param The list data type.
31 | */
32 | public interface AsyncList extends AsyncCollection {
33 |
34 | /**
35 | * Gets a value at a specific index in the list.
36 | *
37 | * @param index The index of the value to get.
38 | * @param resultHandler An asynchronous handler to be called with the value result.
39 | */
40 | void get(int index, Handler> resultHandler);
41 |
42 | /**
43 | * Sets an index in the list.
44 | *
45 | * @param index The index to set.
46 | * @param value The value to set.
47 | */
48 | void set(int index, T value);
49 |
50 | /**
51 | * Sets an index in the list.
52 | *
53 | * @param index The index to set.
54 | * @param value The value to set.
55 | * @param doneHandler An asynchronous handler to be called once complete.
56 | */
57 | void set(int index, T value, Handler> doneHandler);
58 |
59 | /**
60 | * Removes an index in the list.
61 | *
62 | * @param index The index to remove.
63 | */
64 | void remove(int index);
65 |
66 | /**
67 | * Removes an index in the list.
68 | *
69 | * @param index The index to remove.
70 | * @param doneHandler An asynchronous handler to be called once complete. The handler
71 | * result will be the value that was removed from the list.
72 | */
73 | void remove(int index, Handler> doneHandler);
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/AsyncQueue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data;
17 |
18 | import org.vertx.java.core.AsyncResult;
19 | import org.vertx.java.core.Handler;
20 |
21 | /**
22 | * Asynchronous queue.
23 | *
24 | * If the current Vert.x instance is a Hazelcast clustered instance,
25 | * the queue will be backed by a Hazelcast queue. Otherwise, the queue
26 | * will be backed by a Vert.x shared data map.
27 | *
28 | * @author Jordan Halterman
29 | *
30 | * @param The queue data type.
31 | */
32 | public interface AsyncQueue extends AsyncCollection {
33 |
34 | /**
35 | * Inserts the element into the queue if it's immediately possible to do so.
36 | *
37 | * @param value The value to insert.
38 | */
39 | void offer(T value);
40 |
41 | /**
42 | * Inserts the element into the queue if it's immediately possible to do so.
43 | *
44 | * @param value The value to insert.
45 | * @param doneHandler An asynchronous handler to be called once complete.
46 | */
47 | void offer(T value, Handler> doneHandler);
48 |
49 | /**
50 | * Retrieves but does not remove the head of the queue.
51 | *
52 | * @param resultHandler An asynchronous handler to be called with the result.
53 | */
54 | void element(Handler> resultHandler);
55 |
56 | /**
57 | * Retrieves but does not remove the head of the queue. If there is no value at the
58 | * head of the queue then the result value will be null
.
59 | *
60 | * @param resultHandler An asynchronous handler to be called with the result.
61 | */
62 | void peek(Handler> resultHandler);
63 |
64 | /**
65 | * Retrieves and removed the head of the queue. If there is no value at the
66 | * head of the queue then the result value will be null
.
67 | *
68 | * @param resultHandler An asynchronous handler to be called with the result.
69 | */
70 | void poll(Handler> resultHandler);
71 |
72 | /**
73 | * Retrieves and removed the head of the queue.
74 | *
75 | * @param resultHandler An asynchronous handler to be called with the result.
76 | */
77 | void remove(Handler> resultHandler);
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/AsyncSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data;
17 |
18 | /**
19 | * Asynchronous set.
20 | *
21 | * If the current Vert.x instance is a Hazelcast clustered instance,
22 | * the set will be backed by a Hazelcast set. Otherwise, the set
23 | * will be backed by a Vert.x shared data set.
24 | *
25 | * @author Jordan Halterman
26 | *
27 | * @param The set data type.
28 | */
29 | public interface AsyncSet extends AsyncCollection {
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/DataException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * Data exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class DataException extends VertigoException {
27 |
28 | public DataException(String message) {
29 | super(message);
30 | }
31 |
32 | public DataException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public DataException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/data/impl/AsyncDataStructure.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.data.impl;
17 |
18 | import net.kuujo.vertigo.cluster.impl.ClusterLocator;
19 |
20 | import org.vertx.java.core.AsyncResult;
21 | import org.vertx.java.core.Handler;
22 | import org.vertx.java.core.Vertx;
23 | import org.vertx.java.core.impl.DefaultFutureResult;
24 |
25 | /**
26 | * Base asynchronous data structure.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | class AsyncDataStructure {
31 | protected final String address;
32 | protected final String name;
33 | protected final Vertx vertx;
34 | private final ClusterLocator clusterLocator;
35 | private String localAddress;
36 | private long lastReset;
37 | private long check;
38 |
39 | public AsyncDataStructure(String address, String name, Vertx vertx) {
40 | this.address = address;
41 | this.name = name;
42 | this.vertx = vertx;
43 | this.clusterLocator = new ClusterLocator(vertx);
44 | }
45 |
46 | public String name() {
47 | return name;
48 | }
49 |
50 | /**
51 | * Checks whether the local cluster address needs to be updated.
52 | */
53 | protected void checkAddress() {
54 | if (localAddress == null) {
55 | check++;
56 | if (check > 1000 && System.currentTimeMillis() - lastReset > 15000) {
57 | resetLocalAddress(null);
58 | }
59 | }
60 | }
61 |
62 | /**
63 | * Updates the known local group address.
64 | */
65 | protected void resetLocalAddress(final Handler> doneHandler) {
66 | localAddress = null;
67 | lastReset = System.currentTimeMillis();
68 | clusterLocator.locateCluster(address, new Handler>() {
69 | @Override
70 | public void handle(AsyncResult result) {
71 | if (result.succeeded() && result.result() != null) {
72 | localAddress = result.result();
73 | new DefaultFutureResult(true).setHandler(doneHandler);
74 | } else {
75 | new DefaultFutureResult(false).setHandler(doneHandler);
76 | }
77 | }
78 | });
79 | }
80 |
81 | /**
82 | * Returns the local address if available, otherwise a group address.
83 | */
84 | protected final String localOrGroupAddress() {
85 | return localAddress != null ? localAddress : address;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/ClusterManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager;
17 |
18 | import net.kuujo.vertigo.service.Service;
19 |
20 | /**
21 | * Server-side cluster manager.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | public interface ClusterManager extends Service {
26 |
27 | /**
28 | * Returns the cluster address.
29 | *
30 | * @return The cluster address.
31 | */
32 | String address();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/GroupManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager;
17 |
18 | import net.kuujo.vertigo.service.Service;
19 |
20 | /**
21 | * Server-side group manager.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | public interface GroupManager extends Service {
26 |
27 | /**
28 | * Returns the group address.
29 | *
30 | * @return The group address.
31 | */
32 | String address();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/NodeManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager;
17 |
18 | import net.kuujo.vertigo.service.Service;
19 |
20 | /**
21 | * Manages a server-side node.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | public interface NodeManager extends Service {
26 |
27 | /**
28 | * Returns the node address.
29 | *
30 | * @return The node address.
31 | */
32 | String address();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/ClusterAgent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import net.kuujo.vertigo.cluster.manager.ClusterManager;
19 | import net.kuujo.vertigo.cluster.manager.GroupManager;
20 | import net.kuujo.vertigo.cluster.manager.NodeManager;
21 | import net.kuujo.vertigo.platform.PlatformManager;
22 | import net.kuujo.vertigo.platform.impl.DefaultPlatformManager;
23 | import net.kuujo.vertigo.util.Addresses;
24 | import net.kuujo.vertigo.util.ContextManager;
25 | import net.kuujo.vertigo.util.CountingCompletionHandler;
26 |
27 | import org.vertx.java.core.AsyncResult;
28 | import org.vertx.java.core.Future;
29 | import org.vertx.java.core.Handler;
30 | import org.vertx.java.platform.Verticle;
31 |
32 | /**
33 | * Vertigo cluster verticle.
34 | *
35 | * @author Jordan Halterman
36 | */
37 | public class ClusterAgent extends Verticle {
38 | private ClusterManager cluster;
39 | private GroupManager group;
40 | private NodeManager node;
41 |
42 | @Override
43 | public void start(final Future startResult) {
44 | boolean localOnly = container.config().getBoolean("local", false);
45 | String clusterName = container.config().getString("cluster", "vertigo");
46 | String groupName = container.config().getString("group", "DEFAULT");
47 | String nodeAddress = container.config().getString("node", Addresses.createUniqueAddress());
48 | PlatformManager platform = new DefaultPlatformManager(vertx, container);
49 | ClusterListener listener = new ClusterListenerFactory(vertx).createClusterListener(localOnly);
50 | ClusterData data = new ClusterDataFactory(vertx).createClusterData(localOnly);
51 | cluster = new DefaultClusterManager(clusterName, vertx, new ContextManager(vertx), platform, listener, data);
52 | group = new DefaultGroupManager(String.format("%s.%s", clusterName, groupName), clusterName, vertx, new ContextManager(vertx), platform, listener, data);
53 | node = new DefaultNodeManager(String.format("%s.%s.%s", clusterName, groupName, nodeAddress), String.format("%s.%s", clusterName, groupName), clusterName, vertx, new ContextManager(vertx), platform, listener, data);
54 | final CountingCompletionHandler counter = new CountingCompletionHandler(3);
55 | counter.setHandler(new Handler>() {
56 | @Override
57 | public void handle(AsyncResult result) {
58 | if (result.failed()) {
59 | startResult.setFailure(result.cause());
60 | } else {
61 | startResult.setResult((Void) null);
62 | }
63 | }
64 | });
65 | cluster.start(counter);
66 | group.start(counter);
67 | node.start(counter);
68 | }
69 |
70 | @Override
71 | public void stop() {
72 | cluster.stop();
73 | group.stop();
74 | node.stop();
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/ClusterData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import java.util.List;
19 | import java.util.Map;
20 | import java.util.Queue;
21 | import java.util.Set;
22 |
23 | import com.hazelcast.core.MultiMap;
24 |
25 | /**
26 | * Cluster data provider.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | interface ClusterData {
31 |
32 | MultiMap getMultiMap(String name);
33 |
34 | Map getMap(String name);
35 |
36 | Set getSet(String name);
37 |
38 | List getList(String name);
39 |
40 | Queue getQueue(String name);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/ClusterDataFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import org.vertx.java.core.Vertx;
19 |
20 | import com.hazelcast.core.HazelcastInstance;
21 |
22 | /**
23 | * Cluster data provider factory.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | class ClusterDataFactory {
28 | private final Vertx vertx;
29 |
30 | ClusterDataFactory(Vertx vertx) {
31 | this.vertx = vertx;
32 | }
33 |
34 | /**
35 | * Creates cluster data.
36 | *
37 | * @param localOnly Indicates whether to force the cluster to be local only.
38 | * @return A cluster data store.
39 | */
40 | public ClusterData createClusterData(boolean localOnly) {
41 | if (localOnly) return new VertxClusterData(vertx);
42 | HazelcastInstance hazelcast = ClusterListenerFactory.getHazelcastInstance(vertx);
43 | if (hazelcast != null) {
44 | return new HazelcastClusterData(hazelcast);
45 | } else {
46 | return new VertxClusterData(vertx);
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/ClusterListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import org.vertx.java.core.Handler;
19 |
20 | /**
21 | * Cluster membership listener.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | interface ClusterListener {
26 |
27 | /**
28 | * Returns the local unique node ID.
29 | *
30 | * @return The node ID of the local node.
31 | */
32 | String nodeId();
33 |
34 | /**
35 | * Registers a cluster join handler.
36 | *
37 | * @param handler The handler to register.
38 | */
39 | void registerJoinHandler(Handler handler);
40 |
41 | /**
42 | * Unregisters a cluster join handler.
43 | *
44 | * @param handler The handler to unregister.
45 | */
46 | void unregisterJoinHandler(Handler handler);
47 |
48 | /**
49 | * Registers a cluster leave handler.
50 | *
51 | * @param handler The handler to register.
52 | */
53 | void registerLeaveHandler(Handler handler);
54 |
55 | /**
56 | * Unregisters a cluster leave handler.
57 | *
58 | * @param handler The handler to unregister.
59 | */
60 | void unregisterLeaveHandler(Handler handler);
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/ClusterListenerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import java.lang.reflect.Field;
19 |
20 | import org.vertx.java.core.Vertx;
21 | import org.vertx.java.core.impl.VertxInternal;
22 | import org.vertx.java.core.spi.cluster.ClusterManager;
23 |
24 | import com.hazelcast.core.HazelcastInstance;
25 |
26 | /**
27 | * Cluster membership listener factory.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | class ClusterListenerFactory {
32 | private final Vertx vertx;
33 |
34 | ClusterListenerFactory(Vertx vertx) {
35 | this.vertx = vertx;
36 | }
37 |
38 | /**
39 | * Returns the Vert.x Hazelcast instance if one exists.
40 | *
41 | * @param vertx The current Vert.x instance.
42 | * @return The Vert.x Hazelcast instance if Vert.x is clustered.
43 | */
44 | static HazelcastInstance getHazelcastInstance(Vertx vertx) {
45 | VertxInternal vertxInternal = (VertxInternal) vertx;
46 | ClusterManager clusterManager = vertxInternal.clusterManager();
47 | if (clusterManager != null) {
48 | Class> clazz = clusterManager.getClass();
49 | Field field;
50 | try {
51 | field = clazz.getDeclaredField("hazelcast");
52 | field.setAccessible(true);
53 | return HazelcastInstance.class.cast(field.get(clusterManager));
54 | } catch (Exception e) {
55 | return null;
56 | }
57 | }
58 | return null;
59 | }
60 |
61 | /**
62 | * Creates a cluster listener.
63 | *
64 | * @param localOnly Indicates whether to force the cluster to be local only.
65 | * @return A new cluster listener.
66 | */
67 | public ClusterListener createClusterListener(boolean localOnly) {
68 | if (localOnly) return new NoClusterListener();
69 | HazelcastInstance hazelcast = getHazelcastInstance(vertx);
70 | if (hazelcast != null) {
71 | return new HazelcastClusterListener(hazelcast, vertx);
72 | } else {
73 | return new NoClusterListener();
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/HazelcastClusterData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import java.util.List;
19 | import java.util.Map;
20 | import java.util.Queue;
21 | import java.util.Set;
22 |
23 | import com.hazelcast.core.HazelcastInstance;
24 | import com.hazelcast.core.MultiMap;
25 |
26 | /**
27 | * Hazelcast-based cluster data provider.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | class HazelcastClusterData implements ClusterData {
32 | private final HazelcastInstance hazelcast;
33 |
34 | public HazelcastClusterData(HazelcastInstance hazelcast) {
35 | this.hazelcast = hazelcast;
36 | }
37 |
38 | @Override
39 | public MultiMap getMultiMap(String name) {
40 | return hazelcast.getMultiMap(name);
41 | }
42 |
43 | @Override
44 | public Map getMap(String name) {
45 | return hazelcast.getMap(name);
46 | }
47 |
48 | @Override
49 | public Set getSet(String name) {
50 | return hazelcast.getSet(name);
51 | }
52 |
53 | @Override
54 | public List getList(String name) {
55 | return hazelcast.getList(name);
56 | }
57 |
58 | @Override
59 | public Queue getQueue(String name) {
60 | return hazelcast.getQueue(name);
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/cluster/manager/impl/NoClusterListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.cluster.manager.impl;
17 |
18 | import java.util.UUID;
19 |
20 | import org.vertx.java.core.Handler;
21 |
22 | /**
23 | * Fake cluster listener for non-clustered Vert.x instances.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | class NoClusterListener implements ClusterListener {
28 | private final String id = UUID.randomUUID().toString();
29 |
30 | @Override
31 | public String nodeId() {
32 | return id;
33 | }
34 |
35 | @Override
36 | public void registerJoinHandler(Handler handler) {
37 | // Do nothing useful.
38 | }
39 |
40 | @Override
41 | public void unregisterJoinHandler(Handler handler) {
42 | // Do nothing useful.
43 | }
44 |
45 | @Override
46 | public void registerLeaveHandler(Handler handler) {
47 | // Do nothing useful.
48 | }
49 |
50 | @Override
51 | public void unregisterLeaveHandler(Handler handler) {
52 | // Do nothing useful.
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/ComponentException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * A component exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class ComponentException extends VertigoException {
27 |
28 | public ComponentException(String message) {
29 | super(message);
30 | }
31 |
32 | public ComponentException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public ComponentException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/ComponentFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.component;
17 |
18 | import net.kuujo.vertigo.cluster.Cluster;
19 |
20 | import org.vertx.java.core.Vertx;
21 | import org.vertx.java.platform.Container;
22 |
23 | /**
24 | * Component factory.
25 | *
26 | * @author Jordan Halterman
27 | */
28 | public interface ComponentFactory {
29 |
30 | /**
31 | * Sets the factory Vertx instance.
32 | *
33 | * @param vertx A Vertx instance.
34 | * @return The called factory instance.
35 | */
36 | ComponentFactory setVertx(Vertx vertx);
37 |
38 | /**
39 | * Sets the factory Container instance.
40 | *
41 | * @param container A Vert.x container.
42 | * @return The called factory instance.
43 | */
44 | ComponentFactory setContainer(Container container);
45 |
46 | /**
47 | * Creates a component.
48 | *
49 | * @param context The component instance context.
50 | * @param cluster The cluster to which the component belongs.
51 | * @return A new component instance.
52 | */
53 | Component createComponent(InstanceContext context, Cluster cluster);
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/InstanceContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component;
17 |
18 | import net.kuujo.vertigo.Context;
19 | import net.kuujo.vertigo.component.impl.DefaultInstanceContext;
20 | import net.kuujo.vertigo.io.InputContext;
21 | import net.kuujo.vertigo.io.OutputContext;
22 |
23 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
24 |
25 | /**
26 | * A component instance context which contains information regarding a specific component
27 | * (module or verticle) instance within a network.
28 | *
29 | * The instance context is the primary immutable configuration used by
30 | * each instance of a component verticle or module to construct its input
31 | * and output ports/connections. Note that the context is observable, and
32 | * component instance observe the context for changes within the cluster
33 | * in order to support runtime network configuration changes by automatically
34 | * updating their input and output connections when the context changes.
35 | *
36 | * @author Jordan Halterman
37 | */
38 | @JsonTypeInfo(
39 | use=JsonTypeInfo.Id.CLASS,
40 | include=JsonTypeInfo.As.PROPERTY,
41 | property="class",
42 | defaultImpl=DefaultInstanceContext.class
43 | )
44 | public interface InstanceContext extends Context {
45 |
46 | /**
47 | * Returns the instance number.
48 | *
49 | * @return The instance number.
50 | */
51 | int number();
52 |
53 | /**
54 | * Returns the instance address.
55 | *
56 | * This is simply a unique identifier used to identify the component
57 | * across all networks.
58 | *
59 | * @return The instance address.
60 | */
61 | String address();
62 |
63 | /**
64 | * Returns the instance status address.
65 | *
66 | * The status address is used by the component instance to notify
67 | * the network and other components within the network of its current
68 | * status. This is used by the network manager to coordinate startup
69 | * of components across a network.
70 | *
71 | * @return The instance status address.
72 | */
73 | String status();
74 |
75 | /**
76 | * Returns the instance input context.
77 | *
78 | * @return The instance input context.
79 | */
80 | InputContext input();
81 |
82 | /**
83 | * Returns the instance output context.
84 | *
85 | * @return The instance output context.
86 | */
87 | OutputContext output();
88 |
89 | /**
90 | * Returns the parent component context.
91 | *
92 | * @return The parent component context.
93 | */
94 | @SuppressWarnings("rawtypes")
95 | T component();
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/ModuleConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component;
17 |
18 | import net.kuujo.vertigo.component.impl.DefaultModuleConfig;
19 |
20 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 |
22 | /**
23 | * Module component configuration.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | @JsonTypeInfo(
28 | use=JsonTypeInfo.Id.CLASS,
29 | include=JsonTypeInfo.As.PROPERTY,
30 | property="class",
31 | defaultImpl=DefaultModuleConfig.class
32 | )
33 | public interface ModuleConfig extends ComponentConfig {
34 |
35 | /**
36 | * module
is a string indicating the module name. This field is required
37 | * for all module components.
38 | */
39 | public static final String MODULE_NAME = "module";
40 |
41 | /**
42 | * Sets the module name.
43 | *
44 | * @param moduleName The module name.
45 | * @return The module configuration.
46 | * @throws IllegalArgumentException If the module name is not a valid module identifier.
47 | */
48 | ModuleConfig setModule(String moduleName);
49 |
50 | /**
51 | * Gets the module name.
52 | *
53 | * @return The module name.
54 | */
55 | String getModule();
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/ModuleContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component;
17 |
18 | import net.kuujo.vertigo.component.impl.DefaultModuleContext;
19 |
20 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 |
22 | /**
23 | * Module component context.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | @JsonTypeInfo(
28 | use=JsonTypeInfo.Id.CLASS,
29 | include=JsonTypeInfo.As.PROPERTY,
30 | property="class",
31 | defaultImpl=DefaultModuleContext.class
32 | )
33 | public interface ModuleContext extends ComponentContext {
34 |
35 | /**
36 | * Returns the module name.
37 | *
38 | * @return The module name.
39 | */
40 | String module();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/VerticleContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component;
17 |
18 | import net.kuujo.vertigo.component.impl.DefaultVerticleContext;
19 |
20 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 |
22 | /**
23 | * Verticle component context.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | @JsonTypeInfo(
28 | use=JsonTypeInfo.Id.CLASS,
29 | include=JsonTypeInfo.As.PROPERTY,
30 | property="class",
31 | defaultImpl=DefaultVerticleContext.class
32 | )
33 | public interface VerticleContext extends ComponentContext {
34 |
35 | /**
36 | * Returns the verticle main.
37 | *
38 | * @return The verticle main.
39 | */
40 | String main();
41 |
42 | /**
43 | * Returns a boolean indicating whether the verticle is a worker verticle.
44 | *
45 | * @return Indicates whether the verticle is a worker verticle.
46 | */
47 | boolean isWorker();
48 |
49 | /**
50 | * Returns a boolean indicating whether the verticle is a worker and is multi-threaded.
51 | * If the verticle is not a worker then false
will be returned.
52 | *
53 | * @return Indicates whether the verticle is a worker and is multi-threaded.
54 | */
55 | boolean isMultiThreaded();
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/impl/DefaultComponentFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component.impl;
17 |
18 | import net.kuujo.vertigo.cluster.Cluster;
19 | import net.kuujo.vertigo.component.Component;
20 | import net.kuujo.vertigo.component.ComponentFactory;
21 | import net.kuujo.vertigo.component.InstanceContext;
22 |
23 | import org.vertx.java.core.Vertx;
24 | import org.vertx.java.platform.Container;
25 |
26 | /**
27 | * Default component factory implementation.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | public class DefaultComponentFactory implements ComponentFactory {
32 | private Vertx vertx;
33 | private Container container;
34 |
35 | public DefaultComponentFactory() {
36 | }
37 |
38 | public DefaultComponentFactory(Vertx vertx, Container container) {
39 | setVertx(vertx);
40 | setContainer(container);
41 | }
42 |
43 | @Override
44 | public ComponentFactory setVertx(Vertx vertx) {
45 | this.vertx = vertx;
46 | return this;
47 | }
48 |
49 | @Override
50 | public ComponentFactory setContainer(Container container) {
51 | this.container = container;
52 | return this;
53 | }
54 |
55 | @Override
56 | public Component createComponent(InstanceContext context, Cluster cluster) {
57 | return new DefaultComponent(context, vertx, container, cluster);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/impl/DefaultModuleConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component.impl;
17 |
18 | import net.kuujo.vertigo.component.ModuleConfig;
19 | import net.kuujo.vertigo.network.NetworkConfig;
20 | import net.kuujo.vertigo.util.Args;
21 |
22 | import org.vertx.java.platform.impl.ModuleIdentifier;
23 |
24 | import com.fasterxml.jackson.annotation.JsonSetter;
25 |
26 | /**
27 | * Default module configuration implementation.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | public class DefaultModuleConfig extends DefaultComponentConfig implements ModuleConfig {
32 | private String module;
33 |
34 | public DefaultModuleConfig() {
35 | super();
36 | }
37 |
38 | public DefaultModuleConfig(String name, String moduleName, NetworkConfig network) {
39 | setName(name);
40 | setModule(moduleName);
41 | }
42 |
43 | @Override
44 | public Type getType() {
45 | return Type.MODULE;
46 | }
47 |
48 | @Override
49 | @JsonSetter("module")
50 | public ModuleConfig setModule(String moduleName) {
51 | Args.checkNotNull(moduleName, "module name cannot be null");
52 | // Instantiate a module identifier to force it to validate the module name.
53 | // If the module name is invalid then an IllegalArgumentException will be thrown.
54 | new ModuleIdentifier(moduleName);
55 | this.module = moduleName;
56 | return this;
57 | }
58 |
59 | @Override
60 | public String getModule() {
61 | return module;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/component/impl/DefaultVerticleConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.component.impl;
17 |
18 | import net.kuujo.vertigo.component.VerticleConfig;
19 | import net.kuujo.vertigo.network.NetworkConfig;
20 | import net.kuujo.vertigo.util.Args;
21 |
22 | import com.fasterxml.jackson.annotation.JsonProperty;
23 | import com.fasterxml.jackson.annotation.JsonSetter;
24 |
25 | /**
26 | * Default verticle configuration implementation.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | public class DefaultVerticleConfig extends DefaultComponentConfig implements VerticleConfig {
31 | private String main;
32 | private boolean worker = false;
33 | @JsonProperty("multi-threaded")
34 | private boolean multiThreaded = false;
35 |
36 | public DefaultVerticleConfig() {
37 | super();
38 | }
39 |
40 | public DefaultVerticleConfig(String name, String main, NetworkConfig network) {
41 | setName(name);
42 | setMain(main);
43 | }
44 |
45 | @Override
46 | public Type getType() {
47 | return Type.VERTICLE;
48 | }
49 |
50 | @Override
51 | @JsonSetter("main")
52 | public VerticleConfig setMain(String main) {
53 | Args.checkNotNull(main, "verticle main must not be null");
54 | this.main = main;
55 | return this;
56 | }
57 |
58 | @Override
59 | public String getMain() {
60 | return main;
61 | }
62 |
63 | @Override
64 | public VerticleConfig setWorker(boolean isWorker) {
65 | this.worker = isWorker;
66 | if (!worker) {
67 | multiThreaded = false;
68 | }
69 | return this;
70 | }
71 |
72 | @Override
73 | public boolean isWorker() {
74 | return worker;
75 | }
76 |
77 | @Override
78 | public VerticleConfig setMultiThreaded(boolean isMultiThreaded) {
79 | this.multiThreaded = isMultiThreaded;
80 | return this;
81 | }
82 |
83 | @Override
84 | public boolean isMultiThreaded() {
85 | return multiThreaded;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/ComponentHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | import net.kuujo.vertigo.component.Component;
19 |
20 | /**
21 | * Hook type for component events.
22 | *
23 | * Component hooks can be added to specific components through the
24 | * network configuration API. All component hooks are serializable
25 | * using the default Jackson-based json serializer.
26 | *
27 | * @author Jordan Halterman
28 | */
29 | public interface ComponentHook extends IOHook {
30 |
31 | /**
32 | * Called when the component has started.
33 | *
34 | * @param component The component that was started.
35 | */
36 | void handleStart(Component component);
37 |
38 | /**
39 | * Called when the component has stopped.
40 | *
41 | * @param component The component that was stopped.
42 | */
43 | void handleStop(Component component);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/EventBusHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | import net.kuujo.vertigo.component.Component;
19 | import net.kuujo.vertigo.component.InstanceContext;
20 | import net.kuujo.vertigo.util.Contexts;
21 |
22 | import org.vertx.java.core.eventbus.EventBus;
23 | import org.vertx.java.core.json.JsonObject;
24 |
25 | import com.fasterxml.jackson.annotation.JsonIgnore;
26 |
27 | /**
28 | * Event bus based hook implementation.
29 | *
30 | * This hook publishes events to the event bus. Messages are published to the
31 | * given address. If no address is provided then messages will be published
32 | * to the internal address of the component to which the hook is attached.
33 | *
34 | * Messages are formatted as {@link JsonObject} instances. Each message will have
35 | * an event
key which indicates the event that occurred. Additional
36 | * keys depend on the event.
37 | *
38 | * You can use an {@link EventBusHookListener} to listen for messages from an
39 | * EventBusHook
. This listener will handle parsing messages and
40 | * calling event handlers.
41 | *
42 | * @author Jordan Halterman
43 | */
44 | public class EventBusHook implements ComponentHook {
45 | @JsonIgnore private InstanceContext context;
46 | @JsonIgnore private EventBus eventBus;
47 | private String address;
48 |
49 | public EventBusHook() {
50 | }
51 |
52 | public EventBusHook(String address) {
53 | this.address = address;
54 | }
55 |
56 | @Override
57 | public void handleStart(Component component) {
58 | this.eventBus = component.vertx().eventBus();
59 | this.context = component.context();
60 | if (this.address == null) {
61 | this.address = component.context().component().address();
62 | }
63 | eventBus.publish(address, new JsonObject().putString("event", "start").putObject("context", Contexts.serialize(context)));
64 | }
65 |
66 | @Override
67 | public void handleSend(Object message) {
68 | eventBus.publish(address, new JsonObject().putString("event", "send").putValue("message", message));
69 | }
70 |
71 | @Override
72 | public void handleReceive(Object message) {
73 | eventBus.publish(address, new JsonObject().putString("event", "receive").putValue("message", message));
74 | }
75 |
76 | @Override
77 | public void handleStop(Component subject) {
78 | eventBus.publish(address, new JsonObject().putString("event", "stop").putObject("context", Contexts.serialize(context)));
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/Hook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | import net.kuujo.vertigo.util.serialization.JsonSerializable;
19 |
20 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 |
22 | /**
23 | * Base type for hooking into Vertigo events.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="hook")
28 | public interface Hook extends JsonSerializable {
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/IOHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | /**
19 | * Hook type for listening for input/output message events.
20 | *
21 | * @author Jordan Halterman
22 | */
23 | public interface IOHook extends InputHook, OutputHook {
24 | }
25 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/InputHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | /**
19 | * Hook type for listening for input message events.
20 | *
21 | * @author Jordan Halterman
22 | */
23 | public interface InputHook extends Hook {
24 |
25 | /**
26 | * Called when a message has been received on the input.
27 | *
28 | * @param message The message that was received.
29 | */
30 | void handleReceive(Object message);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/MetricsHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | import net.kuujo.vertigo.component.Component;
19 | import net.kuujo.vertigo.component.InstanceContext;
20 |
21 | import org.vertx.java.core.eventbus.EventBus;
22 | import org.vertx.java.core.json.JsonObject;
23 |
24 | import com.fasterxml.jackson.annotation.JsonIgnore;
25 |
26 | /**
27 | * This hook integrates directly with the mod-metrics module by
28 | * Tim Yates. To add the hook to a component, simply instantiate
29 | * the hook with the event bus address of the mod-metrics module.
30 | *
31 | *
32 | * network.addVerticle("foo", Foo.class.getName()).addHook(new MetricsHook("com.bloidonia.metrics"));
33 | *
34 | *
35 | * @author Jordan Halterman
36 | */
37 | public class MetricsHook implements ComponentHook {
38 | @JsonIgnore private InstanceContext context;
39 | @JsonIgnore private EventBus eventBus;
40 | private String address;
41 |
42 | public MetricsHook() {
43 | }
44 |
45 | public MetricsHook(String address) {
46 | this.address = address;
47 | }
48 |
49 | @Override
50 | public void handleStart(Component component) {
51 | context = component.context();
52 | eventBus = component.vertx().eventBus();
53 | }
54 |
55 | @Override
56 | public void handleReceive(Object message) {
57 | eventBus.send(address, new JsonObject()
58 | .putString("action", "mark")
59 | .putString("name", String.format("%s.receive", context.address())));
60 | }
61 |
62 | @Override
63 | public void handleSend(Object message) {
64 | eventBus.send(address, new JsonObject()
65 | .putString("action", "mark")
66 | .putString("name", String.format("%s.send", context.address())));
67 | }
68 |
69 | @Override
70 | public void handleStop(Component component) {
71 |
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/hook/OutputHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.hook;
17 |
18 | /**
19 | * Hook type for listening for output message events.
20 | *
21 | * @author Jordan Halterman
22 | */
23 | public interface OutputHook extends Hook {
24 |
25 | /**
26 | * Called when a message has been sent on the output.
27 | *
28 | * @param message The message that was sent.
29 | */
30 | void handleSend(Object message);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/Closeable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import org.vertx.java.core.AsyncResult;
19 | import org.vertx.java.core.Handler;
20 |
21 | /**
22 | * Closeable type.
23 | *
24 | * @author Jordan Halterman
25 | *
26 | * @param The closeable type.
27 | */
28 | public interface Closeable> extends AutoCloseable {
29 |
30 | /**
31 | * Closes the stream.
32 | */
33 | void close();
34 |
35 | /**
36 | * Closes the stream.
37 | *
38 | * @param doneHandler An asynchronous handler to be called once complete.
39 | */
40 | void close(Handler> doneHandler);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/IOCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import net.kuujo.vertigo.io.port.Port;
19 |
20 | /**
21 | * Input/output collector.
22 | *
23 | * Collectors are simple interfaces to collections of ports.
24 | *
25 | * @author Jordan Halterman
26 | *
27 | * @param The collector type.
28 | */
29 | public interface IOCollector> extends Openable, Closeable {
30 |
31 | /**
32 | * Returns a named port.
33 | *
34 | * @param name The port name.
35 | * @return A named port.
36 | */
37 | @SuppressWarnings("rawtypes")
38 | Port port(String name);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/IOContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import net.kuujo.vertigo.Context;
19 | import net.kuujo.vertigo.component.InstanceContext;
20 |
21 | /**
22 | * Input/output context.
23 | *
24 | * @author Jordan Halterman
25 | */
26 | public interface IOContext> extends Context {
27 |
28 | /**
29 | * Returns the parent instance context.
30 | *
31 | * @return The parent instance context.
32 | */
33 | InstanceContext instance();
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/IOException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * I/O exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class IOException extends VertigoException {
27 |
28 | public IOException(String message) {
29 | super(message);
30 | }
31 |
32 | public IOException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public IOException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/Input.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import net.kuujo.vertigo.io.group.InputGroupSupport;
19 |
20 | import org.vertx.java.core.Handler;
21 | import org.vertx.java.core.Vertx;
22 |
23 | /**
24 | * Basic input interface.
25 | *
26 | * @author Jordan Halterman
27 | *
28 | * @param The input type.
29 | */
30 | public interface Input> extends InputGroupSupport {
31 |
32 | /**
33 | * Returns the input's vertx instance.
34 | *
35 | * @return The inputs Vert.x instance.
36 | */
37 | Vertx vertx();
38 |
39 | /**
40 | * Pauses the input.
41 | *
42 | * When the input is paused, messages received by the input will be buffered,
43 | * so it is important that inputs not be paused for too long if messages
44 | * continue to flow.
45 | *
46 | * @return The input.
47 | */
48 | T pause();
49 |
50 | /**
51 | * Resumes receiving data on the input.
52 | *
53 | * When the input is resumed, any messages that were buffered during the pause
54 | * will be processed first. Once the input's buffer is empty it will resume
55 | * normal operation.
56 | *
57 | * @return The input.
58 | */
59 | T resume();
60 |
61 | /**
62 | * Registers a message handler on the input.
63 | *
64 | * The message handler can accept any message type that is supported by
65 | * the Vert.x event bus. Vertigo messages cannot be replied to and do not
66 | * need to be acked. The input handles communicating and coordinating with
67 | * outputs internally.
68 | *
69 | * @param handler A message handler.
70 | * @return The input.
71 | */
72 | T messageHandler(Handler handler);
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/InputCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import java.util.Collection;
19 |
20 | import net.kuujo.vertigo.io.port.InputPort;
21 |
22 | /**
23 | * Interface for receiving messages on input ports.
24 | *
25 | * The input collector is the primary interface for receiving input within a component
26 | * instance. Input collectors are simple wrappers around {@link InputPort} instances.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | public interface InputCollector extends IOCollector {
31 |
32 | /**
33 | * Returns a collection of input ports.
34 | *
35 | * @return A collection of input ports.
36 | */
37 | Collection ports();
38 |
39 | /**
40 | * Returns an input port.
41 | *
42 | * If the port doesn't already exist then the input collector will lazily
43 | * create the port. Ports can be referenced prior to the input event starting
44 | * up, and once the input starts ports will be properly configured.
45 | *
46 | * @param name The name of the port to load.
47 | * @return The input port.
48 | */
49 | InputPort port(String name);
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/InputContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import java.util.Collection;
19 |
20 | import net.kuujo.vertigo.io.impl.DefaultInputContext;
21 | import net.kuujo.vertigo.io.port.InputPortContext;
22 |
23 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
24 |
25 | /**
26 | * Input context is a wrapper around input port information for
27 | * a single component instance.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | @JsonTypeInfo(
32 | use=JsonTypeInfo.Id.CLASS,
33 | include=JsonTypeInfo.As.PROPERTY,
34 | property="class",
35 | defaultImpl=DefaultInputContext.class
36 | )
37 | public interface InputContext extends IOContext {
38 |
39 | /**
40 | * Returns the input's port contexts.
41 | *
42 | * @return A collection of input port contexts.
43 | */
44 | Collection ports();
45 |
46 | /**
47 | * Returns the input port context for a given port.
48 | *
49 | * @param name The name of the port to return.
50 | * @return The input port context.
51 | */
52 | InputPortContext port(String name);
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/Openable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import org.vertx.java.core.AsyncResult;
19 | import org.vertx.java.core.Handler;
20 |
21 | /**
22 | * An openable type.
23 | *
24 | * @author Jordan Halterman
25 | *
26 | * @param The openable type.
27 | */
28 | public interface Openable> {
29 |
30 | /**
31 | * Opens the stream.
32 | *
33 | * @return The stream.
34 | */
35 | T open();
36 |
37 | /**
38 | * Opens the stream.
39 | *
40 | * @param doneHandler An asynchronous handler to be called once complete.
41 | * @return The stream.
42 | */
43 | T open(Handler> doneHandler);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/OutputCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import java.util.Collection;
19 |
20 | import net.kuujo.vertigo.io.port.OutputPort;
21 |
22 | /**
23 | * Interface for sending messages on output ports.
24 | *
25 | * The output collector exposes a simple interface to {@link OutputPort} instances
26 | * through which messages can be sent.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | public interface OutputCollector extends IOCollector {
31 |
32 | /**
33 | * Returns a collection of output ports.
34 | *
35 | * @return A collection of output ports.
36 | */
37 | Collection ports();
38 |
39 | /**
40 | * Returns an output port.
41 | *
42 | * If the port doesn't already exist then the input collector will lazily
43 | * create the port. Ports can be referenced prior to the output event starting
44 | * up, and once the output starts ports will be properly configured.
45 | *
46 | * @param name The name of the port to load.
47 | * @return An output port.
48 | */
49 | OutputPort port(String name);
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/OutputContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io;
17 |
18 | import java.util.Collection;
19 |
20 | import net.kuujo.vertigo.io.impl.DefaultOutputContext;
21 | import net.kuujo.vertigo.io.port.OutputPortContext;
22 |
23 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
24 |
25 | /**
26 | * Output context is a wrapper around output port information for
27 | * a single component instance.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | @JsonTypeInfo(
32 | use=JsonTypeInfo.Id.CLASS,
33 | include=JsonTypeInfo.As.PROPERTY,
34 | property="class",
35 | defaultImpl=DefaultOutputContext.class
36 | )
37 | public interface OutputContext extends IOContext {
38 |
39 | /**
40 | * Returns the output's port contexts.
41 | *
42 | * @return A collection of output port contexts.
43 | */
44 | Collection ports();
45 |
46 | /**
47 | * Returns the output port context for a given port.
48 | *
49 | * @param name The name of the port to return.
50 | * @return The output port context.
51 | */
52 | OutputPortContext port(String name);
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/batch/InputBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.batch;
17 |
18 | import net.kuujo.vertigo.io.Input;
19 | import net.kuujo.vertigo.io.group.InputGroupSupport;
20 |
21 | import org.vertx.java.core.Handler;
22 |
23 | /**
24 | * Receivable batch of messages.
25 | *
26 | * Input batches are received when an output batch is created and sent.
27 | * Each input batch has a beginning and end, and Vertigo guarantees that
28 | * a batch will not receive messages until its start handler is called
29 | * and will not receive messages after its end handler is called.
30 | *
31 | * @author Jordan Halterman
32 | */
33 | public interface InputBatch extends MessageBatch, Input, InputGroupSupport {
34 |
35 | /**
36 | * Registers a start handler on the batch.
37 | *
38 | * @param handler A handler to be called when the batch is started.
39 | * @return The input batch.
40 | */
41 | InputBatch startHandler(Handler handler);
42 |
43 | /**
44 | * Registers an end handler on the batch.
45 | *
46 | * @param handler A handler to be called when the batch is ended.
47 | * @return The input batch.
48 | */
49 | InputBatch endHandler(Handler handler);
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/batch/InputBatchSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.batch;
17 |
18 | import org.vertx.java.core.Handler;
19 |
20 | /**
21 | * Support for receiving input batches.
22 | *
23 | * @author Jordan Halterman
24 | *
25 | * @param The type to which the support belongs.
26 | */
27 | public interface InputBatchSupport> {
28 |
29 | /**
30 | * Registers a batch handler.
31 | *
32 | * @param handler The handler to register. This handler will be called
33 | * whenever a new batch is started.
34 | * @return The called object.
35 | */
36 | T batchHandler(Handler handler);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/batch/MessageBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.batch;
17 |
18 | /**
19 | * Base interface for batches. Batches represent collections of messages over time.
20 | *
21 | * As opposed to groups, batches are collections of messages that can be
22 | * sent to any target component instance. Batches simply delimit a group
23 | * of messages output from a given component during a time window.
24 | *
25 | * @author Jordan Halterman
26 | *
27 | * @param The batch type.
28 | */
29 | public interface MessageBatch> {
30 |
31 | /**
32 | * Returns the unique batch ID.
33 | *
34 | * @return The unique batch ID.
35 | */
36 | String id();
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/batch/OutputBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.batch;
17 |
18 | import net.kuujo.vertigo.io.Output;
19 | import net.kuujo.vertigo.io.group.OutputGroupSupport;
20 |
21 | /**
22 | * Sendable batch of messages.
23 | *
24 | * Output batches represent collections of messages during a time window.
25 | * Each port may only have one batch associated with it at any given time,
26 | * and only once the batch has been ended can the next batch be created.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | public interface OutputBatch extends MessageBatch, Output, OutputGroupSupport {
31 |
32 | /**
33 | * Ends the batch.
34 | */
35 | void end();
36 |
37 | /**
38 | * Ends the batch.
39 | *
40 | * @param args Arguments to the batch's end handler.
41 | */
42 | void end(T args);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/batch/OutputBatchSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.batch;
17 |
18 | import org.vertx.java.core.Handler;
19 |
20 | /**
21 | * Support for creating output batches.
22 | *
23 | * @author Jordan Halterman
24 | *
25 | * @param The type to which the support belongs.
26 | */
27 | public interface OutputBatchSupport> {
28 |
29 | /**
30 | * Creates a new output batch with a random identifier.
31 | *
32 | * @param handler A handler to be called once the batch has been created.
33 | * @return The called object.
34 | */
35 | T batch(Handler handler);
36 |
37 | /**
38 | * Creates a new output batch.
39 | *
40 | * @param args Arguments to the batch's start handler.
41 | * @param handler A handler to be called once the batch has been created.
42 | * @return The called object.
43 | */
44 | T batch(Object args, Handler handler);
45 |
46 | /**
47 | * Creates a new output batch.
48 | *
49 | * @param id The unique batch identifier.
50 | * @param args Arguments to the batch's start handler.
51 | * @param handler A handler to be called once the batch has been created.
52 | * @return The called object.
53 | */
54 | T batch(String id, Object args, Handler handler);
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/Connection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection;
17 |
18 | import net.kuujo.vertigo.io.Closeable;
19 | import net.kuujo.vertigo.io.Openable;
20 |
21 | /**
22 | * Connection between two instances of two components.
23 | *
24 | * When a connection is created between two components, each component
25 | * instance will create a single connection for each instance of the
26 | * component to which it is connected. Connections are inherently
27 | * uni-directional, so each connection has an input and an output side.
28 | *
29 | * @author Jordan Halterman
30 | *
31 | * @param The connection type.
32 | */
33 | public interface Connection> extends Openable, Closeable {
34 |
35 | /**
36 | * Returns the connection address.
37 | *
38 | * @return The connection address.
39 | */
40 | String address();
41 |
42 | /**
43 | * Returns the current connection size.
44 | *
45 | * @return The current connection size.
46 | */
47 | int size();
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/ConnectionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * A connection exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class ConnectionException extends VertigoException {
27 |
28 | public ConnectionException(String message) {
29 | super(message);
30 | }
31 |
32 | public ConnectionException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public ConnectionException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/InputConnection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection;
17 |
18 | import net.kuujo.vertigo.io.Input;
19 | import net.kuujo.vertigo.io.batch.InputBatch;
20 | import net.kuujo.vertigo.io.batch.InputBatchSupport;
21 | import net.kuujo.vertigo.io.group.InputGroupSupport;
22 |
23 | import org.vertx.java.core.Handler;
24 |
25 | /**
26 | * Input connection represents the receiving side of a connection
27 | * between two instances of two components.
28 | *
29 | * Messages on input connections must be received in order. Output
30 | * and input connections keep track of message order by tagging and
31 | * comparing messages with monotonically increasing unique identifiers.
32 | * If the input connection receives a message out of order, it will
33 | * immediately notify the output connection of the last known ordered
34 | * message, indicating that the output connection should resend messages
35 | * after the last known correct message.
36 | *
37 | * The input connection will periodically send messages to the output
38 | * connection indicating the last correct message received, allowing the
39 | * output to clear its queue.
40 | *
41 | * @author Jordan Halterman
42 | */
43 | public interface InputConnection extends Connection, Input, InputGroupSupport, InputBatchSupport {
44 |
45 | /**
46 | * Returns the input connection context.
47 | *
48 | * @return The input connection context.
49 | */
50 | InputConnectionContext context();
51 |
52 | /**
53 | * Registers an input batch handler.
54 | *
55 | * @param handler A handler to be called when an input batch is started.
56 | * @return The input connection.
57 | */
58 | InputConnection batchHandler(Handler handler);
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/InputConnectionContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.hook.InputHook;
21 | import net.kuujo.vertigo.io.connection.impl.DefaultInputConnectionContext;
22 | import net.kuujo.vertigo.io.port.InputPortContext;
23 |
24 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
25 |
26 | /**
27 | * Input connection context represents a single instance's input from
28 | * an instance of another component.
29 | *
30 | * @author Jordan Halterman
31 | */
32 | @JsonTypeInfo(
33 | use=JsonTypeInfo.Id.CLASS,
34 | include=JsonTypeInfo.As.PROPERTY,
35 | property="class",
36 | defaultImpl=DefaultInputConnectionContext.class
37 | )
38 | public interface InputConnectionContext extends ConnectionContext {
39 |
40 | /**
41 | * Returns the parent input port context.
42 | *
43 | * @return The parent port context.
44 | */
45 | InputPortContext port();
46 |
47 | /**
48 | * Returns a list of input hooks.
49 | *
50 | * @return A list of input hooks.
51 | */
52 | List hooks();
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/OutputConnection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection;
17 |
18 | import net.kuujo.vertigo.io.Output;
19 | import net.kuujo.vertigo.io.connection.impl.ConnectionOutputBatch;
20 | import net.kuujo.vertigo.io.group.OutputGroupSupport;
21 |
22 | import org.vertx.java.core.Handler;
23 |
24 | /**
25 | * Output connection.
26 | *
27 | * Output connections represent a direct connection between two instances
28 | * of separate components. Each output connection points to a single
29 | * input connection which receives messages from this connection and this
30 | * connection only.
31 | *
32 | * When the connection is opened, it will attempt to connect to the
33 | * corresponding input connection (the other side of the connection) by
34 | * periodically sending connect
messages to the input connection.
35 | * Once the input connection replies to the output connection, the connection
36 | * is opened.
37 | *
38 | * The output connection sends messages for the connection and on behalf
39 | * of any groups created on the connection. Each message that is sent
40 | * by the output connection is tagged with a monotonically increasing
41 | * number. The connection listens for messages indicating that a message
42 | * was received out of order. If a message was received out of order, the
43 | * output connection will begin resending messages from the last known
44 | * correct message.
45 | *
46 | * @author Jordan Halterman
47 | */
48 | public interface OutputConnection extends Connection, Output, OutputGroupSupport {
49 |
50 | /**
51 | * Returns the output connection context.
52 | *
53 | * @return The output connection context.
54 | */
55 | OutputConnectionContext context();
56 |
57 | /**
58 | * Creates an output batch on the connection.
59 | *
60 | * @param id The unique batch ID.
61 | * @param args Arguments to the batch's start handler.
62 | * @param handler A handler to be called once the batch is started.
63 | * @return The output connection.
64 | */
65 | OutputConnection batch(String id, Object args, Handler handler);
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/OutputConnectionContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.hook.OutputHook;
21 | import net.kuujo.vertigo.io.connection.impl.DefaultOutputConnectionContext;
22 | import net.kuujo.vertigo.io.stream.OutputStreamContext;
23 |
24 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
25 |
26 | /**
27 | * Output connection context represents a single instance's output to
28 | * an instance of another component.
29 | *
30 | * @author Jordan Halterman
31 | */
32 | @JsonTypeInfo(
33 | use=JsonTypeInfo.Id.CLASS,
34 | include=JsonTypeInfo.As.PROPERTY,
35 | property="class",
36 | defaultImpl=DefaultOutputConnectionContext.class
37 | )
38 | public interface OutputConnectionContext extends ConnectionContext {
39 |
40 | /**
41 | * Returns the parent output stream context.
42 | *
43 | * @return The parent stream context.
44 | */
45 | OutputStreamContext stream();
46 |
47 | /**
48 | * Returns a list of output hooks.
49 | *
50 | * @return A list of output hooks.
51 | */
52 | List hooks();
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/impl/ConnectionInputBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection.impl;
17 |
18 | import net.kuujo.vertigo.io.batch.InputBatch;
19 |
20 | /**
21 | * Connection level input batch.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | public interface ConnectionInputBatch extends InputBatch {
26 | }
27 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/impl/ConnectionInputGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection.impl;
17 |
18 | import net.kuujo.vertigo.io.group.InputGroup;
19 |
20 | /**
21 | * Connection level input group.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | public interface ConnectionInputGroup extends InputGroup {
26 | }
27 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/impl/ConnectionOutputBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection.impl;
17 |
18 | import net.kuujo.vertigo.io.connection.OutputConnection;
19 |
20 | /**
21 | * Connection level output batch.
22 | *
23 | * The connection output batch is an extension of the {@link OutputConnection} that
24 | * allows batch connections to be selected during routing.
25 | *
26 | * @author Jordan Halterman
27 | */
28 | public interface ConnectionOutputBatch extends OutputConnection {
29 |
30 | /**
31 | * Returns the batch ID.
32 | *
33 | * @return The unique batch ID.
34 | */
35 | String id();
36 |
37 | /**
38 | * Ends the batch.
39 | */
40 | void end();
41 |
42 | /**
43 | * Ends the batch.
44 | *
45 | * @param args Arguments to the batch's end handler.
46 | */
47 | void end(T args);
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/connection/impl/ConnectionOutputGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.connection.impl;
17 |
18 | import net.kuujo.vertigo.io.group.OutputGroup;
19 |
20 | /**
21 | * Connection level output group.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | public interface ConnectionOutputGroup extends OutputGroup {
26 | }
27 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/group/InputGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.group;
17 |
18 | import net.kuujo.vertigo.io.Input;
19 |
20 | import org.vertx.java.core.Handler;
21 |
22 | /**
23 | * Input groups represent collections of input messages.
24 | *
25 | * In order for an input group to receive messages, an output group
26 | * of the same name must have sent messages from the other side of
27 | * the connection. Each time an output group is created a corresponding
28 | * input group will be created on the other side of the connection.
29 | *
30 | * Input groups use a very particular order of operations. When a new
31 | * group message is received on an input connection, the connection will
32 | * create a corresponding input group. The group will not receive any
33 | * messages until it has registered a message handler. Once a message
34 | * handler has been registered, the input group will notify the
35 | * corresponding output group that it's prepared to accept messages.
36 | * This allows time for input groups to call asynchronous APIs during
37 | * setup.
38 | *
39 | * Input group messages will be received in strong order just as all
40 | * other Vertigo messages. The input group uses the underlying connection
41 | * to validate message ordering. This ordering helps guarantee that
42 | * all child groups will be ended before the parent is ended. This allows
43 | * inputs to reliably create and destroy state using start and end handlers.
44 | *
45 | * @author Jordan Halterman
46 | */
47 | public interface InputGroup extends MessageGroup, Input {
48 |
49 | /**
50 | * Registers a start handler on the group.
51 | *
52 | * @param handler A handler to be called when the group is started.
53 | * @return The input group.
54 | */
55 | InputGroup startHandler(Handler handler);
56 |
57 | /**
58 | * Registers an end handler on the group.
59 | *
60 | * @param handler A handler to be called when the group is ended.
61 | * @return The input group.
62 | */
63 | InputGroup endHandler(Handler handler);
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/group/InputGroupSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.group;
17 |
18 | import org.vertx.java.core.Handler;
19 |
20 | /**
21 | * Support for receiving input groups.
22 | *
23 | * @author Jordan Halterman
24 | *
25 | * @param The type to which the support belongs.
26 | */
27 | public interface InputGroupSupport> {
28 |
29 | /**
30 | * Registers a group handler.
31 | *
32 | * @param handler The handler to register. This handler will be called
33 | * whenever any group on the input is started.
34 | * @return The called object.
35 | */
36 | T groupHandler(Handler handler);
37 |
38 | /**
39 | * Registers a group handler.
40 | *
41 | * @param name The name of the group for which to register the handler.
42 | * @param handler The handler to register. This handler will be called
43 | * whenever a group of the given name is started.
44 | * @return The called object.
45 | */
46 | T groupHandler(String name, Handler handler);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/group/MessageGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.group;
17 |
18 | /**
19 | * Input/output group.
20 | *
21 | * Groups are named logical collections of messages between two instances
22 | * of two components. When a group is created, the group will be assigned
23 | * to a single target instance per connection. Groups can be nested.
24 | *
25 | * @author Jordan Halterman
26 | */
27 | public interface MessageGroup> {
28 |
29 | /**
30 | * Returns the unique group identifier.
31 | *
32 | * @return The unique group identifier.
33 | */
34 | String id();
35 |
36 | /**
37 | * Returns the group name.
38 | *
39 | * @return The group name.
40 | */
41 | String name();
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/group/OutputGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.group;
17 |
18 | import net.kuujo.vertigo.io.Output;
19 |
20 | /**
21 | * Output group represent collections of output messages.
22 | *
23 | * Output groups represent structured groups of output messages. Users can
24 | * use output groups to batch messages in a manner that will be similarly
25 | * represented on input connections. When messages are grouped, Vertigo
26 | * guarantees that the other side of the connection(s) will see each of
27 | * the messages within the group. Additionally, sub-groups may be created,
28 | * and Vertigo guarantees that sub-groups are sent and ended prior to parent
29 | * groups ending. This allows for logical grouping of messages.
30 | *
31 | * All messages within a root level output group will be sent on the same
32 | * connection. In other words, connection selection is performed per-group
33 | * rather than per-message.
34 | *
35 | * Grouped messages are guaranteed to be ordered just as all Vertigo messages
36 | * are. However, some components of a group are not ordered. Specifically, if
37 | * a group is ended before all of its children (groups) have ended, the parent
38 | * group will wait for the children to end before sending its own end message.
39 | * This helps Vertigo guarantee that when all children of a group have completed
40 | * before a parent completing.
41 | *
42 | * @author Jordan Halterman
43 | */
44 | public interface OutputGroup extends MessageGroup, Output {
45 |
46 | /**
47 | * Ends the output group.
48 | */
49 | void end();
50 |
51 | /**
52 | * Ends the output group.
53 | *
54 | * @param args Arguments to the group's end handler.
55 | */
56 | void end(T args);
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/group/OutputGroupSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.group;
17 |
18 | import org.vertx.java.core.Handler;
19 |
20 | /**
21 | * Support for creating output groups.
22 | *
23 | * @author Jordan Halterman
24 | *
25 | * @param The type to which the support belongs.
26 | */
27 | public interface OutputGroupSupport> {
28 |
29 | /**
30 | * Creates a uniquely named output group.
31 | *
32 | * Messages sent through groups will always be sent to the same
33 | * connection(s). Groups can also be nested.
34 | *
35 | * @param handler A handler to be called once the group has been setup.
36 | * @return The called object.
37 | */
38 | T group(Handler handler);
39 |
40 | /**
41 | * Creates a named output group.
42 | *
43 | * Messages sent through groups will always be sent to the same
44 | * connection(s). Groups can also be nested.
45 | *
46 | * @param name The output group name.
47 | * @param handler A handler to be called once the group has been setup.
48 | * @return The called object.
49 | */
50 | T group(String name, Handler handler);
51 |
52 | /**
53 | * Creates a named output group.
54 | *
55 | * Messages sent through groups will always be sent to the same
56 | * connection(s). Groups can also be nested.
57 | *
58 | * @param name The output group name.
59 | * @param args Arguments to the group's start handler.
60 | * @param handler A handler to be called once the group has been setup.
61 | * @return The called object.
62 | */
63 | T group(String name, Object args, Handler handler);
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/impl/DefaultIOContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.impl;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Collection;
20 |
21 | import net.kuujo.vertigo.component.impl.DefaultInstanceContext;
22 | import net.kuujo.vertigo.impl.BaseContext;
23 | import net.kuujo.vertigo.io.IOContext;
24 | import net.kuujo.vertigo.io.port.impl.DefaultOutputPortContext;
25 |
26 | import com.fasterxml.jackson.annotation.JsonIgnore;
27 |
28 | /**
29 | * Input/output context.
30 | *
31 | * @author Jordan Halterman
32 | */
33 | abstract class DefaultIOContext> extends BaseContext {
34 | protected Collection streams = new ArrayList<>();
35 | @JsonIgnore
36 | protected DefaultInstanceContext instance;
37 |
38 | /**
39 | * Sets the input parent.
40 | */
41 | @SuppressWarnings("unchecked")
42 | public T setInstanceContext(DefaultInstanceContext instance) {
43 | this.instance = instance;
44 | return (T) this;
45 | }
46 |
47 | /**
48 | * Returns the parent instance context.
49 | *
50 | * @return The parent instance context.
51 | */
52 | public DefaultInstanceContext instance() {
53 | return instance;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/logging/PortLoggerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.logging;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | import net.kuujo.vertigo.io.OutputCollector;
22 | import net.kuujo.vertigo.util.Args;
23 |
24 | import org.vertx.java.core.logging.impl.LoggerFactory;
25 |
26 | /**
27 | * Port logger factory.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | public class PortLoggerFactory {
32 | private static final Map> loggers = new HashMap<>();
33 |
34 | /**
35 | * Creates an output port logger for the given type.
36 | *
37 | * @param clazz The type being logged.
38 | * @param output The output to which to log messages.
39 | * @return An output port logger.
40 | */
41 | public static PortLogger getLogger(Class> clazz, OutputCollector output) {
42 | return getLogger(clazz.getCanonicalName(), output);
43 | }
44 |
45 | /**
46 | * Creates an output port logger with the given name.
47 | *
48 | * @param name The logger name.
49 | * @param output The output to which to log messages.
50 | * @return An output port logger.
51 | */
52 | public static PortLogger getLogger(String name, OutputCollector output) {
53 | Args.checkNotNull(name, "logger name cannot be null");
54 | Map loggers = PortLoggerFactory.loggers.get(name);
55 | if (loggers == null) {
56 | loggers = new HashMap<>();
57 | PortLoggerFactory.loggers.put(name, loggers);
58 | }
59 |
60 | PortLogger logger = loggers.get(output);
61 | if (logger == null) {
62 | logger = new PortLogger(LoggerFactory.getLogger(name), output);
63 | loggers.put(output, logger);
64 | }
65 | return logger;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/port/InputPort.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.port;
17 |
18 | import net.kuujo.vertigo.io.Input;
19 | import net.kuujo.vertigo.io.batch.InputBatchSupport;
20 | import net.kuujo.vertigo.io.group.InputGroupSupport;
21 |
22 | /**
23 | * Input port on which messages are received.
24 | *
25 | * The input port can contain any number of {@link net.kuujo.vertigo.io.connection.InputConnection}
26 | * on which it receives input messages. Connections are constructed based
27 | * on current network configuration information. When the network configuration
28 | * is updated, the port will automatically update its internal connections.
29 | *
30 | * @author Jordan Halterman
31 | */
32 | public interface InputPort extends Port, Input, InputGroupSupport, InputBatchSupport {
33 | }
34 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/port/InputPortContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.port;
17 |
18 | import java.util.Collection;
19 | import java.util.List;
20 |
21 | import net.kuujo.vertigo.hook.InputHook;
22 | import net.kuujo.vertigo.io.InputContext;
23 | import net.kuujo.vertigo.io.connection.InputConnectionContext;
24 | import net.kuujo.vertigo.io.port.impl.DefaultInputPortContext;
25 |
26 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
27 |
28 | /**
29 | * Input port context represents a set of input connections for a single
30 | * port within a single instance of a component.
31 | *
32 | * @author Jordan Halterman
33 | */
34 | @JsonTypeInfo(
35 | use=JsonTypeInfo.Id.CLASS,
36 | include=JsonTypeInfo.As.PROPERTY,
37 | property="class",
38 | defaultImpl=DefaultInputPortContext.class
39 | )
40 | public interface InputPortContext extends PortContext {
41 |
42 | /**
43 | * Returns the parent input context.
44 | *
45 | * @return The parent input context.
46 | */
47 | InputContext input();
48 |
49 | /**
50 | * Returns a collection of input port connections.
51 | *
52 | * @return A list of input connections.
53 | */
54 | Collection connections();
55 |
56 | /**
57 | * Returns a list of input hooks.
58 | *
59 | * @return A list of port input hooks.
60 | */
61 | List hooks();
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/port/OutputPort.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.port;
17 |
18 | import net.kuujo.vertigo.io.Output;
19 | import net.kuujo.vertigo.io.batch.OutputBatch;
20 | import net.kuujo.vertigo.io.batch.OutputBatchSupport;
21 | import net.kuujo.vertigo.io.group.OutputGroupSupport;
22 |
23 | import org.vertx.java.core.Handler;
24 |
25 | /**
26 | * Output port to which messages are sent.
27 | *
28 | * The output port can contain any number of {@link net.kuujo.vertigo.io.stream.OutputStream}
29 | * to which it sends messages. Each message that is sent on the output port will
30 | * be sent on all underlying streams. Selection occurs within each stream
31 | * rather than at the port level.
32 | *
33 | * Streams are constructed based on current network configuration information.
34 | * When the network configuration is updated, the port will automatically update
35 | * its internal streams.
36 | *
37 | * @author Jordan Halterman
38 | */
39 | public interface OutputPort extends Port, Output, OutputBatchSupport, OutputGroupSupport {
40 |
41 | /**
42 | * Creates a new batch.
43 | *
44 | * @param handler A handler to be called when the batch is created.
45 | * @return The output batch.
46 | */
47 | OutputPort batch(Handler handler);
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/port/OutputPortContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.port;
17 |
18 | import java.util.Collection;
19 | import java.util.List;
20 |
21 | import net.kuujo.vertigo.hook.OutputHook;
22 | import net.kuujo.vertigo.io.OutputContext;
23 | import net.kuujo.vertigo.io.port.impl.DefaultOutputPortContext;
24 | import net.kuujo.vertigo.io.stream.OutputStreamContext;
25 |
26 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
27 |
28 | /**
29 | * Output port context represents a set of output connections for a single
30 | * port within a single instance of a component.
31 | *
32 | * @author Jordan Halterman
33 | */
34 | @JsonTypeInfo(
35 | use=JsonTypeInfo.Id.CLASS,
36 | include=JsonTypeInfo.As.PROPERTY,
37 | property="class",
38 | defaultImpl=DefaultOutputPortContext.class
39 | )
40 | public interface OutputPortContext extends PortContext {
41 |
42 | /**
43 | * Returns the parent output context.
44 | *
45 | * @return The parent output context.
46 | */
47 | OutputContext output();
48 |
49 | /**
50 | * Returns a collection of port streams.
51 | *
52 | * @return A collection of streams in the port.
53 | */
54 | Collection streams();
55 |
56 | /**
57 | * Returns a list of output hooks.
58 | *
59 | * @return A list of port output hooks.
60 | */
61 | List hooks();
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/port/Port.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.port;
17 |
18 | import net.kuujo.vertigo.io.Closeable;
19 | import net.kuujo.vertigo.io.Openable;
20 |
21 | /**
22 | * Input/output port.
23 | *
24 | * Ports represent abstract named interfaces between components. Rather than
25 | * communicating via direct event bus messaging, components send messages to
26 | * output ports and receive messages on input ports. Ports do not have to be
27 | * identically named between components in order to send and receive messages
28 | * to one another. Instead, connections between ports on different components
29 | * are defined in network configurations.
30 | *
31 | * @author Jordan Halterman
32 | */
33 | public interface Port> extends Openable, Closeable {
34 |
35 | /**
36 | * Returns the port name.
37 | *
38 | * @return The port name.
39 | */
40 | String name();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/port/PortContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.port;
17 |
18 | import net.kuujo.vertigo.Context;
19 |
20 | /**
21 | * Base context for input and output port contexts.
22 | *
23 | * @author Jordan Halterman
24 | *
25 | * @param The port type.
26 | */
27 | public interface PortContext> extends Context {
28 |
29 | /**
30 | * Returns the port name.
31 | *
32 | * @return The port name.
33 | */
34 | String name();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/AllSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.io.connection.Connection;
21 |
22 | /**
23 | * Selector that sends messages on all connections.
24 | *
25 | * The *all* selector dispatches messages to all instances of a component.
26 | * Thus, if a component has four instances, all four component workers will
27 | * receive every message emitted to that component.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | public class AllSelector implements Selector {
32 |
33 | public AllSelector() {
34 | }
35 |
36 | @Override
37 | @SuppressWarnings("rawtypes")
38 | public List select(Object message, List connections) {
39 | return connections;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/CustomSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | import net.kuujo.vertigo.io.connection.Connection;
23 | import net.kuujo.vertigo.util.serialization.SerializerFactory;
24 |
25 | import org.vertx.java.core.json.JsonObject;
26 |
27 | import com.fasterxml.jackson.annotation.JsonAnyGetter;
28 | import com.fasterxml.jackson.annotation.JsonAnySetter;
29 |
30 | /**
31 | * Custom selector wrapper.
32 | *
33 | * This class is used only internally by Vertigo to handle custom connection
34 | * selectors. To implement a custom selector, simply extend the base
35 | * {@link Selector} class.
36 | *
37 | * @author Jordan Halterman
38 | */
39 | public class CustomSelector implements Selector {
40 | private Map properties = new HashMap<>();
41 | private boolean initialized;
42 | private Selector selector;
43 |
44 | public CustomSelector() {
45 | }
46 |
47 | public CustomSelector(Selector selector) {
48 | this.selector = selector;
49 | }
50 |
51 | @JsonAnyGetter
52 | private Map getProperties() {
53 | if (selector != null) {
54 | properties = SerializerFactory.getSerializer(selector.getClass()).serializeToObject(selector).toMap();
55 | }
56 | return properties;
57 | }
58 |
59 | @JsonAnySetter
60 | private void setProperty(String name, Object value) {
61 | properties.put(name, value);
62 | }
63 |
64 | private void init() {
65 | if (!initialized) {
66 | String className = (String) properties.get("selector");
67 | if (className != null) {
68 | ClassLoader loader = Thread.currentThread().getContextClassLoader();
69 | try {
70 | Class> clazz = loader.loadClass(className);
71 | selector = (Selector) SerializerFactory.getSerializer(clazz).deserializeObject(new JsonObject(properties), clazz);
72 | } catch (Exception e) {
73 | throw new IllegalArgumentException("Error instantiating serializer factory.");
74 | }
75 | } else {
76 | throw new IllegalStateException("Not a valid custom serializer.");
77 | }
78 | }
79 | }
80 |
81 | @Override
82 | @SuppressWarnings("rawtypes")
83 | public List select(Object message, List connections) {
84 | init();
85 | return selector.select(message, connections);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/FairSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | import net.kuujo.vertigo.io.connection.Connection;
22 |
23 | /**
24 | * Selector that sends messages to the connection with the smallest queue.
25 | *
26 | * The fair selector selects connections based on their current output queue
27 | * sizes. This means the if one connection's queue is backed up, the fair
28 | * selector will evenly dispatch messages to connections with shorter queues.
29 | *
30 | * @author Jordan Halterman
31 | */
32 | public class FairSelector implements Selector {
33 |
34 | @Override
35 | @SuppressWarnings("rawtypes")
36 | public List select(Object message, List connections) {
37 | T lowest = null;
38 | for (T connection : connections) {
39 | if (lowest == null || connection.size() < lowest.size()) {
40 | lowest = connection;
41 | }
42 | }
43 | return Arrays.asList(lowest);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/HashSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.io.connection.Connection;
21 |
22 | /**
23 | * Selector that sends messages based on a simple mod-hash algorithm.
24 | *
25 | * The hash selector is a consistent-hashing based grouping. Given
26 | * a value on which to hash, this grouping guarantees that workers will
27 | * always receive messages with the same values.
28 | *
29 | * @author Jordan Halterman
30 | */
31 | public class HashSelector implements Selector {
32 |
33 | @Override
34 | @SuppressWarnings("rawtypes")
35 | public List select(Object message, List connections) {
36 | int index = Math.abs(message.hashCode() % connections.size());
37 | return connections.subList(index, index+1);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/RandomSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.List;
19 | import java.util.Random;
20 |
21 | import net.kuujo.vertigo.io.connection.Connection;
22 |
23 | /**
24 | * Selector that sends messages to a random connection.
25 | *
26 | * The random selector dispatches messages to component workers randomly.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | public class RandomSelector implements Selector {
31 | private Random rand = new Random();
32 |
33 | public RandomSelector() {
34 | }
35 |
36 | @Override
37 | @SuppressWarnings("rawtypes")
38 | public List select(Object message, List connections) {
39 | int index = rand.nextInt(connections.size());
40 | return connections.subList(index, index+1);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/RoundRobinSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.io.connection.Connection;
21 |
22 | /**
23 | * Selector that sends messages to connections using a simple round-robin algorithm.
24 | *
25 | * The round selector dispatches messages to workers in a round-robin
26 | * fashion.
27 | *
28 | * @author Jordan Halterman
29 | */
30 | public class RoundRobinSelector implements Selector {
31 | private int current;
32 |
33 | public RoundRobinSelector() {
34 | }
35 |
36 | @Override
37 | @SuppressWarnings("rawtypes")
38 | public List select(Object message, List connections) {
39 | int index = current++ % connections.size();
40 | return connections.subList(index, index+1);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/selector/Selector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
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 | package net.kuujo.vertigo.io.selector;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.io.connection.Connection;
21 | import net.kuujo.vertigo.util.serialization.JsonSerializable;
22 |
23 | import com.fasterxml.jackson.annotation.JsonSubTypes;
24 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
25 |
26 | /**
27 | * Connection selector.
28 | *
29 | * Connection selectors are used to route messages between multiple instances
30 | * of a component. When a message is sent on an output stream, the stream's
31 | * selector will select a connection or set of connections to which to copy
32 | * the message.
33 | *
34 | * Vertigo supports custom selector implementations. To implement a custom
35 | * selector, simply implement the {@link Selector} interface as any selector
36 | * implementation does.
37 | *
38 | * @author Jordan Halterman
39 | */
40 | @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type", defaultImpl=CustomSelector.class)
41 | @JsonSubTypes({
42 | @JsonSubTypes.Type(value=RandomSelector.class, name="random"),
43 | @JsonSubTypes.Type(value=RoundRobinSelector.class, name="round-robin"),
44 | @JsonSubTypes.Type(value=HashSelector.class, name="hash"),
45 | @JsonSubTypes.Type(value=FairSelector.class, name="fair"),
46 | @JsonSubTypes.Type(value=AllSelector.class, name="all")
47 | })
48 | public interface Selector extends JsonSerializable {
49 |
50 | /**
51 | * round-robin
is a round robin connection selector.
52 | */
53 | public static final String ROUND_ROBIN = "round-robin";
54 |
55 | /**
56 | * random
is a random connection selector.
57 | */
58 | public static final String RANDOM = "random";
59 |
60 | /**
61 | * hash
is a mod-hash based connection selector.
62 | */
63 | public static final String HASH = "hash";
64 |
65 | /**
66 | * fair
is a selector that selects connections based on lowest queue size.
67 | */
68 | public static final String FAIR = "fair";
69 |
70 | /**
71 | * all
is a selector that routes messages to all connections.
72 | */
73 | public static final String ALL = "all";
74 |
75 | /**
76 | * custom
indicates a custom selector.
77 | */
78 | public static final String CUSTOM = "custom";
79 |
80 | /**
81 | * Selects a list of connections to which to send a message.
82 | *
83 | * @param message The message being sent.
84 | * @param connections A list of connections from which to select.
85 | * @return A list of selected connections.
86 | */
87 | @SuppressWarnings("rawtypes")
88 | List select(Object message, List connections);
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/stream/OutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.stream;
17 |
18 | import net.kuujo.vertigo.io.Closeable;
19 | import net.kuujo.vertigo.io.Openable;
20 | import net.kuujo.vertigo.io.Output;
21 | import net.kuujo.vertigo.io.batch.OutputBatchSupport;
22 | import net.kuujo.vertigo.io.group.OutputGroupSupport;
23 |
24 | /**
25 | * Output stream.
26 | *
27 | * The output stream represents a group of connections between the current
28 | * component instance and multiple instances of another component. Each stream
29 | * uses an internal {@link net.kuujo.vertigo.io.selector.Selector} to select
30 | * connections to which to send each message. Each message sent on a stream
31 | * can be sent to a single connection or it can be copied to multiple connections
32 | * based on the selector implementation.
33 | *
34 | * @author Jordan Halterman
35 | */
36 | public interface OutputStream extends Output, OutputBatchSupport, OutputGroupSupport, Openable, Closeable {
37 |
38 | /**
39 | * Returns the output stream address.
40 | *
41 | * @return The output stream address.
42 | */
43 | String address();
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/io/stream/OutputStreamContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.io.stream;
17 |
18 | import java.util.List;
19 |
20 | import net.kuujo.vertigo.Context;
21 | import net.kuujo.vertigo.io.connection.OutputConnectionContext;
22 | import net.kuujo.vertigo.io.port.OutputPortContext;
23 | import net.kuujo.vertigo.io.selector.Selector;
24 | import net.kuujo.vertigo.io.stream.impl.DefaultOutputStreamContext;
25 |
26 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
27 |
28 | /**
29 | * The output stream context represents a set of output connections
30 | * from one component instance to all instances of another component.
31 | * The context contains information about how to dispatch messages
32 | * between the group of target component instances.
33 | *
34 | * @author Jordan Halterman
35 | */
36 | @JsonTypeInfo(
37 | use=JsonTypeInfo.Id.CLASS,
38 | include=JsonTypeInfo.As.PROPERTY,
39 | property="class",
40 | defaultImpl=DefaultOutputStreamContext.class
41 | )
42 | public interface OutputStreamContext extends Context {
43 |
44 | /**
45 | * Returns the parent output port context.
46 | *
47 | * @return The parent port context.
48 | */
49 | OutputPortContext port();
50 |
51 | /**
52 | * Returns the stream connection selector.
53 | *
54 | * @return The stream connection selector.
55 | */
56 | Selector selector();
57 |
58 | /**
59 | * Returns a list of output connections.
60 | *
61 | * @return A list of output connections.
62 | */
63 | List connections();
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/network/MalformedNetworkException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 the original author or authors.
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 | package net.kuujo.vertigo.network;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * A malformed definition exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class MalformedNetworkException extends VertigoException {
27 |
28 | public MalformedNetworkException(String message) {
29 | super(message);
30 | }
31 |
32 | public MalformedNetworkException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public MalformedNetworkException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/network/NetworkException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.network;
17 |
18 | import net.kuujo.vertigo.VertigoException;
19 |
20 | /**
21 | * A network exception.
22 | *
23 | * @author Jordan Halterman
24 | */
25 | @SuppressWarnings("serial")
26 | public class NetworkException extends VertigoException {
27 |
28 | public NetworkException(String message) {
29 | super(message);
30 | }
31 |
32 | public NetworkException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public NetworkException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/net/kuujo/vertigo/platform/ModuleFields.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
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 | package net.kuujo.vertigo.platform;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import org.vertx.java.core.json.JsonArray;
22 | import org.vertx.java.core.json.JsonObject;
23 |
24 | /**
25 | * Module configuration fields.
26 | *
27 | * @author Jordan Halterman
28 | */
29 | public class ModuleFields extends org.vertx.java.platform.impl.ModuleFields {
30 | private final JsonObject config;
31 |
32 | public ModuleFields(JsonObject config) {
33 | super(config);
34 | this.config = config;
35 | }
36 |
37 | /**
38 | * Returns the value of an arbitray field in the configuration file.
39 | *
40 | * @param name The name of the field to return.
41 | * @return The value of the field as defined in the configuration file.
42 | */
43 | public T getField(String name) {
44 | return config.getValue(name);
45 | }
46 |
47 | /**
48 | * Returns a list of input ports defined by the module.
49 | *
50 | * @return A list of input ports defined by the module.
51 | */
52 | public List getInPorts() {
53 | List