All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.DataStructures.NewHashmap Maven / Gradle / Ivy

package Alachisoft.NCache.Common.DataStructures;

import Alachisoft.NCache.Common.Net.Address;
import Alachisoft.NCache.Common.Util.HashtableUtil;
import com.alachisoft.ncache.serialization.core.io.ICompactSerializable;
import com.alachisoft.ncache.serialization.core.io.NCacheObjectInput;
import com.alachisoft.ncache.serialization.core.io.NCacheObjectOutput;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public final class NewHashmap implements ICompactSerializable {

    private long _lastViewId;
    private java.util.HashMap _map;
    private java.util.ArrayList _members;
    private byte[] _buffer;
    private boolean _updateMap = false;
    private boolean _forcefulUpdate = false;

    public NewHashmap() {
    }

    public NewHashmap(long lastViewid, java.util.HashMap map, java.util.ArrayList
members) { this._lastViewId = lastViewid; this._map = map; this._members = new java.util.ArrayList(members.size()); for (Address address : members) { this._members.add(address.getIpAddress().getHostAddress()); } } public NewHashmap(long viewId, HashMap newMap, List membersList, int bucketSize, boolean b) { } /** * Serialize NewHashmap * * @param instance * @param serializationContext Serialization context used to serialize the * object */ public static void Serialize(NewHashmap instance, String serializationContext, boolean updateClientMap) { java.util.HashMap mapInfo = null; if (instance != null) { mapInfo = new java.util.HashMap(); mapInfo.put("ViewId", instance._lastViewId); mapInfo.put("Members", instance._members); mapInfo.put("Map", instance._map); mapInfo.put("UpdateMap", updateClientMap); mapInfo.put("ForcefulUpdate", instance._forcefulUpdate); ObjectOutputStream objectOutPutStream = null; try { ByteArrayOutputStream byteArrayOutPutStream = new ByteArrayOutputStream(); objectOutPutStream = new ObjectOutputStream(byteArrayOutPutStream); objectOutPutStream.writeObject(mapInfo); instance._buffer = byteArrayOutPutStream.toByteArray(); objectOutPutStream.close(); } catch (IOException e) { } finally { if (objectOutPutStream != null) { try { objectOutPutStream.close(); } catch (IOException ex) { } } } } } /** * Deserialize NewHashmap * * @param serializationContext * @return */ public static NewHashmap Deserialize(byte[] buffer, String serializationContext) { NewHashmap hashmap = null; if (buffer != null && buffer.length > 0) { Object tempVar = null; ObjectInputStream objectInputStream = null; try { objectInputStream = new ObjectInputStream(new ByteArrayInputStream(buffer)); tempVar = objectInputStream.readObject(); objectInputStream.close(); } catch (ClassNotFoundException cls) { System.out.println("" + cls); } catch (IOException e) { System.out.println("" + e); } finally { if (objectInputStream != null) { try { objectInputStream.close(); } catch (IOException ex) { //ex.printStackTrace(); } } } java.util.HashMap map = (java.util.HashMap) ((tempVar instanceof java.util.HashMap) ? tempVar : null); if (map != null) { hashmap = new NewHashmap(); hashmap._lastViewId = (Long) map.get("ViewId"); hashmap._members = (java.util.ArrayList) map.get("Members"); hashmap._map = (java.util.HashMap) map.get("Map"); hashmap._updateMap = (map.get("UpdateMap") != null) ? (Boolean) map.get("UpdateMap") : false; hashmap._forcefulUpdate = (map.get("ForcefulUpdate") != null) ? (Boolean) map.get("ForcefulUpdate") : false; } } return hashmap; } public static NewHashmap DeserializeString(byte[] buffer, String serializationContext) { String strValue = new String(buffer, 0, buffer.length, Charset.forName("UTF-8")); String[] strParts = strValue.split("\t"); NewHashmap hashmap = new NewHashmap(); hashmap._map = HashtableUtil.FromString(strParts[0]); hashmap._members = new ArrayList<>(Arrays.asList(strParts[1].split("\r\n"))); hashmap._lastViewId = Long.parseLong(strParts[2]); hashmap._updateMap = Boolean.getBoolean(strParts[3]); return hashmap; } public boolean isForcefulUpdate() { return _forcefulUpdate; } /** * Last view id that was published */ public long getLastViewId() { return this._lastViewId; } /** * New hash map */ public java.util.HashMap getMap() { return this._map; } /** * Just change the view id */ public boolean getUpdateMap() { return _updateMap; } public void setUpdateMap(boolean value) { _updateMap = value; } /** * List of server members (string representation of IP addresses) */ public java.util.ArrayList getMembers() { return this._members; } /** * Returned the serialized object of NewHashmap */ //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: public byte[] getBuffer() public byte[] getBuffer() { return this._buffer; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("{ ("); builder.append(this._lastViewId); builder.append(") "); builder.append("["); for (int i = 0; i < this.getMembers().size(); i++) { builder.append(this.getMembers().get(i)); if (i < (this.getMembers().size() - 1)) { builder.append(","); } } builder.append("] }"); return builder.toString(); } @Override public void serialize(NCacheObjectOutput writer) throws IOException { writer.writeLong(this._lastViewId); writer.writeObject(this._members); writer.writeObject(this._map); writer.writeBoolean(this._updateMap); writer.writeBoolean(_forcefulUpdate); } @Override public void deserialize(NCacheObjectInput reader) throws IOException, ClassNotFoundException { this._lastViewId = reader.readLong(); this._members = (java.util.ArrayList) reader.readObject(); this._map = (java.util.HashMap) reader.readObject(); this._updateMap = reader.readBoolean(); this._forcefulUpdate = reader.readBoolean(); } } // : ICompactSerializable




© 2015 - 2024 Weber Informatics LLC | Privacy Policy