2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import akka.serialization.JSerializer;
11 import com.google.common.base.Preconditions;
12 import org.apache.commons.lang3.SerializationUtils;
13 import org.opendaylight.controller.cluster.datastore.utils.AbstractBatchedModificationsCursor;
16 * Specialized message transformer, which transforms a {@link ReadyLocalTransaction}
17 * into a {@link BatchedModifications} message. This serializer needs to be plugged
18 * into akka serialization to allow forwarding of ReadyLocalTransaction to remote
21 public final class ReadyLocalTransactionSerializer extends JSerializer {
23 public int identifier() {
28 public boolean includeManifest() {
33 public byte[] toBinary(final Object obj) {
34 Preconditions.checkArgument(obj instanceof ReadyLocalTransaction, "Unsupported object type %s", obj.getClass());
35 final ReadyLocalTransaction readyLocal = (ReadyLocalTransaction) obj;
36 final BatchedModifications batched = new BatchedModifications(readyLocal.getTransactionId(),
37 readyLocal.getRemoteVersion());
38 batched.setDoCommitOnReady(readyLocal.isDoCommitOnReady());
39 batched.setTotalMessagesSent(1);
40 batched.setReady(true);
42 readyLocal.getModification().applyToCursor(new BatchedCursor(batched));
44 return SerializationUtils.serialize(batched);
48 public Object fromBinaryJava(final byte[] bytes, final Class<?> clazz) {
49 return SerializationUtils.deserialize(bytes);
52 private static final class BatchedCursor extends AbstractBatchedModificationsCursor {
53 private final BatchedModifications message;
55 BatchedCursor(final BatchedModifications message) {
56 this.message = Preconditions.checkNotNull(message);
60 protected BatchedModifications getModifications() {