Skip to content

Commit

Permalink
Refactor DistributedGroup to separate all related interfaces and impl…
Browse files Browse the repository at this point in the history
…ementations into subpackages.
  • Loading branch information
kuujo committed Mar 30, 2016
1 parent a0d59d4 commit ee6a072
Show file tree
Hide file tree
Showing 94 changed files with 2,335 additions and 5,752 deletions.
Expand Up @@ -21,6 +21,7 @@
import io.atomix.catalyst.transport.NettyTransport;
import io.atomix.copycat.server.storage.Storage;
import io.atomix.group.DistributedGroup;
import io.atomix.group.task.TaskConsumer;

import java.net.InetAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -66,7 +67,8 @@ public static void main(String[] args) throws Exception {
System.out.println("Joining membership group");
group.join().thenAccept(member -> {
System.out.println("Joined group with member ID: " + member.id());
member.tasks().onTask(task -> {
TaskConsumer<String> consumer = member.tasks().consumer("tasks");
consumer.onTask(task -> {
System.out.println("Received task");
try {
Thread.sleep(100);
Expand All @@ -79,7 +81,7 @@ public static void main(String[] args) throws Exception {
group.onJoin(member -> {
System.out.println(member.id() + " joined the group!");

member.tasks().submit("hello").thenRun(() -> {
member.tasks().producer("tasks").submit("hello").thenRun(() -> {
System.out.println("Task complete!");
});
});
Expand Down
524 changes: 57 additions & 467 deletions group/src/main/java/io/atomix/group/DistributedGroup.java

Large diffs are not rendered by default.

136 changes: 0 additions & 136 deletions group/src/main/java/io/atomix/group/GroupMember.java

This file was deleted.

30 changes: 6 additions & 24 deletions group/src/main/java/io/atomix/group/LocalMember.java
Expand Up @@ -15,12 +15,8 @@
*/
package io.atomix.group;

import io.atomix.group.connection.ConnectionController;
import io.atomix.group.connection.LocalConnection;
import io.atomix.group.state.GroupCommands;
import io.atomix.group.task.LocalTaskQueue;
import io.atomix.group.task.TaskQueueController;
import io.atomix.group.util.Submitter;
import io.atomix.group.messaging.MessageService;
import io.atomix.group.task.TaskService;

import java.util.concurrent.CompletableFuture;

Expand All @@ -44,23 +40,13 @@
*
* @author <a href="http://github.com/kuujo>Jordan Halterman</a>
*/
public class LocalMember extends GroupMember {
final ConnectionController connection;

LocalMember(GroupMemberInfo info, MembershipGroup group, Submitter submitter) {
super(info, group, submitter, new TaskQueueController(new LocalTaskQueue(info.memberId(), group, submitter)));
this.connection = new ConnectionController(new LocalConnection(info.memberId(), info.address(), group.connections));
}
public interface LocalMember extends Member {

@Override
public LocalTaskQueue tasks() {
return (LocalTaskQueue) tasks.queue();
}
MessageService messages();

@Override
public LocalConnection connection() {
return connection.connection();
}
TaskService tasks();

/**
* Leaves the membership group.
Expand All @@ -87,10 +73,6 @@ public LocalConnection connection() {
*
* @return A completable future to be completed once the member has left.
*/
public CompletableFuture<Void> leave() {
return group.submit(new GroupCommands.Leave(memberId)).whenComplete((result, error) -> {
group.members.remove(memberId);
});
}
CompletableFuture<Void> leave();

}
68 changes: 68 additions & 0 deletions group/src/main/java/io/atomix/group/Member.java
@@ -0,0 +1,68 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.atomix.group;

import io.atomix.catalyst.transport.Address;
import io.atomix.group.messaging.MessageClient;
import io.atomix.group.task.TaskClient;

/**
* A {@link DistributedGroup} member representing a member of the group controlled by a local
* or remote process.
*
* @author <a href="http://github.com/kuujo>Jordan Halterman</a>
*/
public interface Member {

/**
* Returns the member ID.
* <p>
* The member ID is guaranteed to be unique across the cluster. Depending on how the member was
* constructed, it may be a user-provided identifier or an automatically generated {@link java.util.UUID}.
*
* @return The member ID.
*/
String id();

/**
* Returns the member address.
*
* @return The member address.
*/
Address address();

/**
* Returns the member properties.
*
* @return The member properties.
*/
PropertiesClient properties();

/**
* Returns the member message service.
*
* @return The member message service.
*/
MessageClient messages();

/**
* Returns the member task service.
*
* @return The member task service.
*/
TaskClient tasks();

}

0 comments on commit ee6a072

Please sign in to comment.