Updated the VoterRegistry.proto file according to the new timestamp of the unsingedBulletinBoardMessage.

Voter-Registry
Vladimir Eliezer Tokarev 2016-03-04 06:02:53 -08:00
parent fea0e8880f
commit 6359f74a7b
5 changed files with 17 additions and 23 deletions

View File

@ -17,12 +17,7 @@ message GroupID{
string id = 1;
}
message VoterGroup{
VoterID voterId = 1;
GroupID groupId = 2;
}
message VoterRegistryMessage{
bytes data = 1;
uint64 CreationMiliseconds = 2;
VoterID voterID = 1;
repeated GroupID groupID = 2;
}

View File

@ -10,7 +10,7 @@ public abstract class RegistryTags {
public final static String VOTER_ENTRY_TAG = "VoterEntry: ";
public final static String VOTER_DATA_TAG = "Data: ";
public final static String GROUP_ID_TAG = "GroupID: ";
public final static String ADD_TO_GROUP_TAG = "AddToGroup: ";
public final static String ADD_TO_GROUP_TAG = "AddToGroups: ";
public final static String VOTE_ACTION_TAG = "VoteAction: ";
}

View File

@ -1,5 +1,6 @@
package meerkat;
import com.google.protobuf.Timestamp;
import meerkat.Registry.BooleanCallBack;
import meerkat.Registry.CollectionMessagesUtils;
import meerkat.Registry.RegistryTags;
@ -62,39 +63,37 @@ public class SimpleRegistry implements VoterRegistry{
}
public void AddVoter(VoterInfo voterInfo, RegistryCallBack callback) {
VoterRegistryMessage.Builder wrapper = VoterRegistryMessage.newBuilder().
setData(voterInfo.toByteString()).setCreationMiliseconds(System.currentTimeMillis());
UnsignedBulletinBoardMessage.Builder basicMessage =
UnsignedBulletinBoardMessage.newBuilder().
addTag(RegistryTags.ID_TAG + voterInfo.getId().getId())
.addTag(RegistryTags.VOTER_ENTRY_TAG)
.addTag(RegistryTags.VOTER_DATA_TAG + voterInfo.getInfo())
.setData(wrapper.build().toByteString());
.setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build());
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
}
public void AddToGroup(VoterGroup voterGroup, RegistryCallBack callback) {
VoterRegistryMessage.Builder wrapper = VoterRegistryMessage.newBuilder().
setData(voterGroup.toByteString()).setCreationMiliseconds(System.currentTimeMillis());
public void AddToGroups(VoterRegistryMessage voterGroup, RegistryCallBack callback) {
UnsignedBulletinBoardMessage.Builder basicMessage =
UnsignedBulletinBoardMessage.newBuilder()
.addTag(RegistryTags.ID_TAG + voterGroup.getVoterId().getId())
.addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupId().getId())
.addTag(RegistryTags.ID_TAG + voterGroup.getVoterID().getId())
.addTag(RegistryTags.ADD_TO_GROUP_TAG)
.setData(wrapper.build().toByteString());
.setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build());
for ( int i = 0 ; i < voterGroup.getGroupIDCount() ; i++)
{
basicMessage.addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupID(i).getId());
}
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
}
public void SetVoted(VoterID voterId, RegistryCallBack callback) {
VoterRegistryMessage.Builder wrapper = VoterRegistryMessage.newBuilder().
setData(voterId.toByteString()).setCreationMiliseconds(System.currentTimeMillis());
UnsignedBulletinBoardMessage.Builder basicMessage =
UnsignedBulletinBoardMessage.newBuilder()
.addTag(RegistryTags.ID_TAG + voterId.getId())
.addTag(RegistryTags.VOTE_ACTION_TAG)
.setData(wrapper.build().toByteString());
.setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build());
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
}

View File

@ -36,7 +36,7 @@ public interface VoterRegistry {
* @param callBack when the adding voter done callBack.HandleResult will be called
* @return true if the adding action succeeded else return false
*/
void AddToGroup(VoterGroup voterGroup, RegistryCallBack callBack);
void AddToGroups(VoterRegistryMessage voterGroup, RegistryCallBack callBack);
/**
* Sets that the voter have voted

View File

@ -232,7 +232,7 @@ public class SimpleRegistryTest extends TestCase {
.setGroupId(GroupID.newBuilder().setId(groupId)).build();
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
registry.AddToGroup(voterInfo, handler);
registry.AddToGroups(voterInfo, handler);
jobSemaphore.acquire();
assertEquals(1, handler.counter);
@ -267,7 +267,7 @@ public class SimpleRegistryTest extends TestCase {
this.certStream = getClass().getResourceAsStream(CERT1_PEM_EXAMPLE);
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient,certStream);
registry.AddToGroup(voterInfo, handler);
registry.AddToGroups(voterInfo, handler);
jobSemaphore.acquire();
assertEquals(1, handler.counter );