Open Kilda Java Documentation
AbstractMessage.java
Go to the documentation of this file.
1 package org.openkilda.wfm.protocol;
2 
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import org.apache.storm.tuple.Fields;
6 
7 import java.util.Arrays;
8 import java.util.List;
9 
10 public abstract class AbstractMessage {
11  public List<Object> pack() throws JsonProcessingException {
12  Fields format = getFormat();
13  Object packed[] = new Object[format.size()];
14 
15  for (int i = 0; i < packed.length; i++) {
16  packed[i] = packField(format.get(i));
17  }
18 
19  return Arrays.asList(packed);
20  }
21 
22  protected Object packField(String fieldId) throws JsonProcessingException {
23  throw new ImplementationError(String.format(
24  "Class %s does not implement packField(\"%s\")",
25  getClass(), fieldId));
26  }
27 
28  abstract protected Fields getFormat();
29 }