本文整理汇总了Java中org.apache.ignite.internal.util.GridUnsafe类的典型用法代码示例。如果您正苦于以下问题:Java GridUnsafe类的具体用法?Java GridUnsafe怎么用?Java GridUnsafe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GridUnsafe类属于org.apache.ignite.internal.util包,在下文中一共展示了GridUnsafe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/**
* Creates settings for specific table.
*
* @param cacheName Ignite cache name.
* @param tableName Cassandra table name.
* @return settings for target Cassandra table.
*/
private KeyValuePersistenceSettings create(String cacheName, String tableName) {
PublicKeyValuePersistenceSettings keyValue = cacheSettings.get(cacheName);
if (keyValue == null) {
keyValue = new PublicKeyValuePersistenceSettings(null, null, defaultKeySettings, defaultValueSettings);
cacheSettings.put(cacheName, keyValue);
}
try {
Object instance = GridUnsafe.allocateInstance(KeyValuePersistenceSettings.class);
set(instance, elvis(keyValue.getTTL(), generalSettings.getTTL()), "ttl");
set(instance, generalSettings.getKeyspace(), "keyspace");
set(instance, tableName, "tbl");
set(instance, elvis(keyValue.getTableOptions(), generalSettings.getTableOptions()), "tblOptions");
set(instance, generalSettings.getKeyspaceOptions(), "keyspaceOptions");
set(instance, elvis(keyValue.getKeyPersistenceSettings(), defaultKeySettings), "keyPersistenceSettings");
set(instance, elvis(keyValue.getValuePersistenceSettings(), defaultValueSettings), "valPersistenceSettings");
return (KeyValuePersistenceSettings)instance;
}
catch (InstantiationException | NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException("Cannot create Settings");
}
}
示例2: writeCharArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void writeCharArray(char[] arr) throws IOException {
writeInt(arr.length);
int bytesToCp = arr.length << 1;
requestFreeSize(bytesToCp);
if (BIG_ENDIAN) {
long off = BYTE_ARR_OFF + this.off;
for (char val : arr) {
GridUnsafe.putCharLE(bytes, off, val);
off += 2;
}
}
else
GridUnsafe.copyMemory(arr, CHAR_ARR_OFF, bytes, BYTE_ARR_OFF + off, bytesToCp);
onWrite(bytesToCp);
}
示例3: writeDoubleArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void writeDoubleArray(double[] val) {
int cnt = val.length << 3;
ensureCapacity(pos + cnt);
if (BIG_ENDIAN) {
for (double item : val) {
writeLongFast(Double.doubleToLongBits(item));
shift(8);
}
}
else
copyAndShift(val, GridUnsafe.DOUBLE_ARR_OFF, cnt);
}
示例4: writeFloatArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void writeFloatArray(float[] val) {
int cnt = val.length << 2;
ensureCapacity(pos + cnt);
if (BIG_ENDIAN) {
for (float item : val) {
writeIntFast(Float.floatToIntBits(item));
shift(4);
}
}
else
copyAndShift(val, GridUnsafe.FLOAT_ARR_OFF, cnt);
}
示例5: toString
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public String toString() {
ByteBuffer buf = ByteBuffer.allocateDirect(pageData.length);
buf.order(ByteOrder.nativeOrder());
buf.put(pageData);
long addr = GridUnsafe.bufferAddress(buf);
try {
return "PageSnapshot [fullPageId = " + fullPageId() + ", page = [\n"
+ PageIO.printPage(addr, pageData.length)
+ "],\nsuper = ["
+ super.toString() + "]]";
}
catch (IgniteCheckedException ignored) {
return "Error during call'toString' of PageSnapshot [fullPageId=" + fullPageId() +
", pageData = " + Arrays.toString(pageData) + ", super=" + super.toString() + "]";
}
finally {
GridUnsafe.cleanDirectBuffer(buf);
}
}
示例6: writeCharArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void writeCharArray(char[] val) {
int cnt = val.length << 1;
ensureCapacity(pos + cnt);
if (BIG_ENDIAN) {
for (char item : val) {
writeCharFast(item);
shift(2);
}
}
else
copyAndShift(val, GridUnsafe.CHAR_ARR_OFF, cnt);
}
示例7: readDoubleArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public double[] readDoubleArray(int cnt) {
int len = cnt << 3;
ensureEnoughData(len);
double[] res = new double[cnt];
if (BIG_ENDIAN) {
for (int i = 0; i < res.length; i++) {
long x = readLongFast();
shift(8);
res[i] = Double.longBitsToDouble(x);
}
}
else
copyAndShift(res, GridUnsafe.DOUBLE_ARR_OFF, len);
return res;
}
示例8: printPage
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected void printPage(long addr, int pageSize, GridStringBuilder sb) throws IgniteCheckedException {
sb.a("TrackingPage [\n\tlastSnapshotTag=").a(getLastSnapshotTag(addr))
.a(",\n\tleftHalf={")
.a("\n\t\tsize=").a(GridUnsafe.getShort(addr + SIZE_FIELD_OFFSET))
.a("\n\t\tdata={");
for (int i = 0; i < (countOfPageToTrack(pageSize) >> 3); i += 2)
sb.appendHex(GridUnsafe.getShort(addr + BITMAP_OFFSET + i));
sb.a("}\n\t},\n\trightHalf={")
.a("\n\t\tsize=").a(GridUnsafe.getShort(addr + BITMAP_OFFSET + (countOfPageToTrack(pageSize) >> 3)))
.a("\n\t\tdata={");
for (int i = 0; i < (countOfPageToTrack(pageSize) >> 3); i += 2)
sb.appendHex(GridUnsafe.getShort(addr + BITMAP_OFFSET + (countOfPageToTrack(pageSize) >> 3)
+ SIZE_FIELD_SIZE + i));
sb.a("}\n\t}\n]");
}
示例9: readHashSet
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/**
* Reads {@link HashSet}.
*
* @param mapFieldOff Map field offset.
* @return Set.
* @throws ClassNotFoundException If class not found.
* @throws IOException In case of error.
*/
@SuppressWarnings("unchecked")
HashSet<?> readHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
try {
HashSet<Object> set = (HashSet<Object>)GridUnsafe.allocateInstance(HashSet.class);
handles.assign(set);
setObject(set, mapFieldOff, readHashMap(true));
return set;
}
catch (InstantiationException e) {
throw new IOException(e);
}
}
示例10: readLinkedHashSet
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/**
* Reads {@link LinkedHashSet}.
*
* @param mapFieldOff Map field offset.
* @return Set.
* @throws ClassNotFoundException If class not found.
* @throws IOException In case of error.
*/
@SuppressWarnings("unchecked")
LinkedHashSet<?> readLinkedHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
try {
LinkedHashSet<Object> set = (LinkedHashSet<Object>)GridUnsafe.allocateInstance(LinkedHashSet.class);
handles.assign(set);
setObject(set, mapFieldOff, readLinkedHashMap(true));
return set;
}
catch (InstantiationException e) {
throw new IOException(e);
}
}
示例11: writeChar
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void writeChar(char val) {
lastFinished = buf.remaining() >= 2;
if (lastFinished) {
int pos = buf.position();
long off = baseOff + pos;
if (BIG_ENDIAN)
GridUnsafe.putCharLE(heapArr, off, val);
else
GridUnsafe.putChar(heapArr, off, val);
buf.position(pos + 2);
}
}
示例12: clearAt
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/**
* @param idx Index to clear value at.
* @param pred Test predicate.
* @param absent Value to return if the cell is empty.
* @return Value at the given index.
*/
public long clearAt(int idx, GridPredicate3<Integer, Long, Integer> pred, long absent) {
long base = entryBase(idx);
int grpId = GridUnsafe.getInt(base);
int tag = GridUnsafe.getInt(base + 4);
long pageId = GridUnsafe.getLong(base + 8);
if ((pageId == REMOVED_PAGE_ID && grpId == REMOVED_CACHE_GRP_ID)
|| (pageId == EMPTY_PAGE_ID && grpId == EMPTY_CACHE_GRP_ID))
return absent;
if (pred.apply(grpId, pageId, tag)) {
long res = valueAt(idx);
setKeyAt(idx, REMOVED_CACHE_GRP_ID, REMOVED_PAGE_ID);
setValueAt(idx, 0);
return res;
}
else
return absent;
}
示例13: readCharArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public char[] readCharArray() throws IOException {
int arrSize = readInt();
int bytesToCp = arrSize << 1;
fromStream(bytesToCp);
char[] arr = new char[arrSize];
long off = BYTE_ARR_OFF + offset(bytesToCp);
if (BIG_ENDIAN) {
for (int i = 0; i < arr.length; i++) {
arr[i] = GridUnsafe.getCharLE(buf, off);
off += 2;
}
}
else
GridUnsafe.copyMemory(buf, off, arr, CHAR_ARR_OFF, bytesToCp);
return arr;
}
示例14: writeLongArray
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void writeLongArray(long[] val) {
int cnt = val.length << 3;
ensureCapacity(pos + cnt);
if (BIG_ENDIAN) {
for (long item : val) {
writeLongFast(item);
shift(8);
}
}
else
copyAndShift(val, GridUnsafe.LONG_ARR_OFF, cnt);
}
示例15: readLong
import org.apache.ignite.internal.util.GridUnsafe; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public long readLong() {
lastFinished = false;
long val = 0;
while (buf.hasRemaining()) {
int pos = buf.position();
byte b = GridUnsafe.getByte(heapArr, baseOff + pos);
buf.position(pos + 1);
prim |= ((long)b & 0x7F) << (7 * primShift);
if ((b & 0x80) == 0) {
lastFinished = true;
val = prim;
if (val == Long.MIN_VALUE)
val = Long.MAX_VALUE;
else
val--;
prim = 0;
primShift = 0;
break;
}
else
primShift++;
}
return val;
}