⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storeditem.java

📁 High performance DB query
💻 JAVA
字号:
/* * @(#)$Id: StoredItem.java,v 1.9 2005/06/17 21:15:26 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.provider.basic;import services.network.Payload;import util.BitID;import util.FreeList;import util.FreeListFactory;import util.network.serialization.GenericByteBuffer;import util.network.serialization.SerializationManager;import util.network.serialization.SerializeBool;import util.network.serialization.SerializeString;/** * Class StoredItem * */public class StoredItem implements Comparable, Payload {    public static long serialVersionUID =        SerializationManager.getSerialUID("overlay.provider.basic.StoredItem");    public String ns;    public String rid;    public int iid;    public Payload object;    public double expiration;    public BitID locationID;    public BitID storageID;    private static FreeList freeList = new FreeList(new StoredItemFactory());    /**     * DeSerialize the object from the provided GenericByteBuffer.     *     * @param inputBuffer     */    public StoredItem(GenericByteBuffer inputBuffer) {        this.ns = SerializeString.deSerialize(inputBuffer);        this.rid = SerializeString.deSerialize(inputBuffer);        this.iid = inputBuffer.getInt();        this.object = SerializationManager.deSerialize(inputBuffer);        this.expiration = inputBuffer.getDouble();        boolean nulls[] = SerializeBool.deSerialize(inputBuffer, 2);        this.locationID = nulls[0]                          ? null                          : new BitID(inputBuffer);        this.storageID = nulls[1]                         ? null                         : new BitID(inputBuffer);    }    /**     * Serialize the object into the provided GenericByteBuffer.     *     * @param outputBuffer     * @return     */    public long serialize(GenericByteBuffer outputBuffer) {        SerializeString.serialize(outputBuffer, ns);        SerializeString.serialize(outputBuffer, rid);        outputBuffer.putInt(iid);        SerializationManager.serialize(outputBuffer, object);        outputBuffer.putDouble(expiration);        SerializeBool.serialize(outputBuffer, (locationID == null),                                (storageID == null));        if (locationID != null) {            locationID.serialize(outputBuffer);        }        if (storageID != null) {            storageID.serialize(outputBuffer);        }        return serialVersionUID;    }    /**     * Constructor StoredItem     */    protected StoredItem() {}    private void init(String ns, String rid, int iid, Payload object,                      double expiration, BitID locationID, BitID storageID) {        this.ns = ns;        this.rid = rid;        this.iid = iid;        this.object = object;        this.expiration = expiration;        this.locationID = locationID;        this.storageID = storageID;    }    /**     * Method getSize     * @return     */    public int getSize() {        int size = ns.length() + rid.length() + Payload.INT_SIZE                   + Payload.DOUBLE_SIZE;        if (object != null) {            size += SerializationManager.getPayloadSize(object);        }        return size;    }    /**     * Method equals     *     * @param other     * @return     */    public boolean equals(Object other) {        StoredItem otherItem = (StoredItem) other;        return (ns.equals(otherItem.ns) && rid.equals(otherItem.rid)                && (iid == otherItem.iid));    }    /**     * Method compareTo     *     * @param other     * @return     */    public int compareTo(Object other) {        StoredItem otherItem = (StoredItem) other;        int nsCompare = ns.compareTo(otherItem.ns);        if (nsCompare != 0) {            return nsCompare;        }        int ridCompare = ns.compareTo(otherItem.rid);        if (ridCompare != 0) {            return ridCompare;        }        if (iid > otherItem.iid) {            return 1;        }        if (iid < otherItem.iid) {            return -1;        }        return 0;    }    /**     * Method toString     * @return     */    public String toString() {        return "<StoredItem: NS:" + ns + ", RID: " + rid + ", IID: " + iid               + ", EX: " + expiration + ">";    }    /**     * Method allocate     *     * @param ns     * @param rid     * @param iid     * @param object     * @param expiration     * @param locationID     * @param storageID     * @return     */    public static StoredItem allocate(String ns, String rid, int iid,                                      Payload object, double expiration,                                      BitID locationID, BitID storageID) {        StoredItem theItem = (StoredItem) freeList.allocate();        theItem.init(ns, rid, iid, object, expiration, locationID, storageID);        return theItem;    }    /**     * Method free     *     * @param theItem     */    public static void free(StoredItem theItem) {        freeList.free(theItem);    }}/** * Class StoredItemFactory * */class StoredItemFactory implements FreeListFactory {    /**     * Method create     * @return     */    public Object create() {        return new StoredItem();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -