51c305cf11f8ece5df152c4c5463fafa851d77dc
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / BarrierReplyMessageFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutputBuilder;
16
17 /**
18  * Translates BarrierReply messages (both OpenFlow v1.0 and OpenFlow v1.3)
19  * @author michal.polkorab
20  * @author timotej.kubas
21  */
22 public class BarrierReplyMessageFactory implements
23         OFDeserializer<BarrierOutput> {
24
25     private static BarrierReplyMessageFactory instance;
26
27     private BarrierReplyMessageFactory() {
28         // do nothing, just singleton
29     }
30
31     /**
32      * @return singleton factory
33      */
34     public static synchronized BarrierReplyMessageFactory getInstance() {
35         if (instance == null) {
36             instance = new BarrierReplyMessageFactory();
37         }
38         return instance;
39     }
40
41     @Override
42     public BarrierOutput bufferToMessage(ByteBuf rawMessage, short version) {
43         BarrierOutputBuilder builder = new BarrierOutputBuilder();
44         builder.setVersion(version);
45         builder.setXid(rawMessage.readUnsignedInt());
46         return builder.build();
47     }
48
49 }