📄 route.java
字号:
/* * @(#)$Id: Route.java,v 1.9 2004/07/02 23:59:20 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704. Attention: Intel License Inquiry. */package overlay.location.can.payload;import java.net.InetSocketAddress;import overlay.location.can.Can;import services.network.Payload;import util.FreeList;import util.FreeListFactory;import util.network.serialization.GenericByteBuffer;import util.network.serialization.SerializationManager;import util.network.serialization.SerializeArray;import util.network.serialization.SerializeBool;/** * The class encapsulates a route message. The route message carries within it * an encapsulated CAN message, as well as the sender address and the * destination coordinates. */public class Route extends CANMessage { public static long serialVersionUID = SerializationManager.getSerialUID("overlay.location.can.payload.Route"); private double[] coordinates; private Payload data; private boolean provideUpCalls; private int hopCount; private int size; private static FreeList freeList = new FreeList(new RouteFactory()); /** * DeSerialize the object from the provided GenericByteBuffer. * * @param inputBuffer */ public Route(GenericByteBuffer inputBuffer) { super(inputBuffer); this.coordinates = SerializeArray.deSerializeDouble(inputBuffer); this.hopCount = inputBuffer.getInt(); this.provideUpCalls = SerializeBool.deSerialize(inputBuffer); this.data = SerializationManager.deSerialize(inputBuffer); this.size = computeSize(); } /** * Serialize the object into the provided GenericByteBuffer. * * @param outputBuffer * @return */ public long serialize(GenericByteBuffer outputBuffer) { super.serialize(outputBuffer); SerializeArray.serializeDouble(outputBuffer, coordinates); outputBuffer.putInt(hopCount); SerializeBool.serialize(outputBuffer, provideUpCalls); SerializationManager.serialize(outputBuffer, data); return serialVersionUID; } /** * Constructor Route */ protected Route() {} private void init(int messageID, InetSocketAddress source, double[] coordinates, Payload data, boolean provideUpCalls) { super.init(messageID, source); this.coordinates = coordinates; this.data = data; this.provideUpCalls = provideUpCalls; this.hopCount = 0; this.size = computeSize(); } private void init(Route message) { super.init(message.messageID, message.source); this.data = message.data; this.coordinates = message.coordinates; this.provideUpCalls = message.provideUpCalls; this.hopCount = message.hopCount; this.size = computeSize(); } private int computeSize() { return super.getSize() + (Payload.DOUBLE_SIZE * Can.DIM) + SerializationManager.getPayloadSize(data) + Payload.INT_SIZE + 1; } /** * Method getSize * @return */ public int getSize() { return size; } /** * Method getCoordinates * @return */ public double[] getCoordinates() { return coordinates; } /** * Method getPayload * @return */ public Payload getPayload() { return data; } /** * Method getProvideUpCalls * @return */ public boolean getProvideUpCalls() { return provideUpCalls; } /** * Method getHopCount * @return */ public int getHopCount() { return hopCount; } /** * Method incrementHopCount * * @param increment */ public void incrementHopCount(int increment) { hopCount += increment; } /** * Method allocate * * @param messageID * @param source * @param coordinates * @param data * @param provideUpCalls * @return */ public static Route allocate(int messageID, InetSocketAddress source, double[] coordinates, Payload data, boolean provideUpCalls) { Route message = (Route) freeList.allocate(); message.init(messageID, source, coordinates, data, provideUpCalls); return message; } /** * Method allocate * * @param oldMessage * @return */ public static Route allocate(Route oldMessage) { Route message = (Route) freeList.allocate(); message.init(oldMessage); return message; } /** * Method free * * @param message */ public static void free(Route message) { freeList.free(message); }}/** * Class RouteFactory * */class RouteFactory implements FreeListFactory { /** * Method create * @return */ public Object create() { return new Route(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -