Exemplo n.º 1
0
 private int mapLogEntryTypeToDatabaseType(LogEntry.Type type) {
   switch (type) {
     case SENTINEL:
       return 0;
     case NOOP:
       return 1;
     case CONFIGURATION:
       return 2;
     case CLIENT:
       return 3;
     default:
       throw new IllegalArgumentException("unrecognized type:" + type.name());
   }
 }
Exemplo n.º 2
0
 private LogEntry newLogEntryFromDatabaseRow(
     LogEntry.Type type, long logIndex, long term, byte[] serializedData) throws IOException {
   switch (type) {
     case SENTINEL:
       checkArgument(
           logIndex == LogEntry.SENTINEL.getIndex(), "mismatched sentinel logIndex:%s", logIndex);
       checkArgument(term == LogEntry.SENTINEL.getTerm(), "mismatched sentinel term:%s", term);
       return LogEntry.SENTINEL;
     case NOOP:
       return new LogEntry.NoopEntry(logIndex, term);
     case CONFIGURATION:
       return new LogEntry.ConfigurationEntry(
           logIndex, term, Sets.<String>newHashSet(), Sets.<String>newHashSet());
     case CLIENT:
       InputStream in = new ByteArrayInputStream(serializedData);
       Command command = commandDeserializer.deserialize(in);
       return new LogEntry.ClientEntry(logIndex, term, command);
     default:
       throw new IllegalArgumentException("unrecognized type:" + type.name());
   }
 }