本文整理汇总了Java中com.addthis.bundle.core.Bundle类的典型用法代码示例。如果您正苦于以下问题:Java Bundle类的具体用法?Java Bundle怎么用?Java Bundle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bundle类属于com.addthis.bundle.core包,在下文中一共展示了Bundle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendColumn
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
public void appendColumn(Bundle bundle, ValueObject value) {
if (value == null) {
// bundles measure non-null values in getCount()
// so appending a null cannot append a column
throw new IllegalArgumentException("cannot append a null column value");
}
checkBinding(bundle);
BundleField field = null;
if (bundle.getCount() < fields.length) {
field = fields[bundle.getCount()];
} else {
BundleField[] newFields = new BundleField[fields.length + 1];
System.arraycopy(fields, 0, newFields, 0, fields.length);
newFields[newFields.length - 1] = bundle.getFormat().getField(Integer.toString(fields.length));
fields = newFields;
field = fields[fields.length - 1];
}
bundle.setValue(field, value);
}
示例2: setValue
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Override public void setValue(Bundle bundle, @Nullable ValueObject value) {
if (value == null) {
bundle.asMap().replaceAll((a, b) -> null);
} else if (array || (value.getObjectType() == ValueObject.TYPE.ARRAY)) {
ValueArray bundleList = bundle.asValueArray();
ValueArray valueList = value.asArray();
int bundleSize = bundleList.size();
int valueSize = valueList.size();
if (valueSize > bundleSize) {
bundleList.addAll(bundleSize, valueList.subList(bundleSize, valueSize));
}
for (int i = 0; i < Math.min(bundleSize, valueSize); i++) {
bundleList.set(i, valueList.get(i));
}
} else {
ValueMap bundleMap = bundle.asValueMap();
ValueMap valueMap = value.asMap();
if (!force && !Sets.intersection(bundleMap.keySet(), valueMap.keySet()).isEmpty()) {
String message = String.format(
"Trying to write value map (%s) to bundle root (%s), at least one field already exists and " +
"force=false", valueMap, bundle);
throw new IllegalArgumentException(message);
}
bundleMap.putAll(valueMap);
}
}
示例3: fromInputStream
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
/**
* decode result from stream
*/
public static void fromInputStream(DataTable result, InputStream in) {
ClassIndexMap classMap = createClassIndexMap();
FieldIndexMap fieldMap = createFieldIndexMap();
try {
long rows = LessBytes.readLength(in);
while (rows-- > 0) {
Bundle row = result.createBundle();
decodeBundle(row, in, fieldMap, classMap);
result.append(row);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例4: testBundleColumnBinder1
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Test
public void testBundleColumnBinder1() {
Bundle b1 = new ListBundle();
BundleColumnBinder binder = new BundleColumnBinder(b1);
b1.setValue(b1.getFormat().getField("abc"), ValueFactory.create("def"));
b1.setValue(b1.getFormat().getField("ghi"), ValueFactory.create("jkl"));
b1.setValue(b1.getFormat().getField("mno"), ValueFactory.create("pqr"));
assertEquals(binder.getColumn(b1, 1), ValueFactory.create("jkl"));
assertEquals(binder.getColumn(b1, 2), ValueFactory.create("pqr"));
assertEquals(binder.getColumn(b1, 0), ValueFactory.create("def"));
assertEquals(binder.getColumn(b1, 3), null);
Bundle b2 = new ListBundle((ListBundleFormat) b1.getFormat());
b2.setValue(b2.getFormat().getField("abc"), ValueFactory.create("def"));
b2.setValue(b2.getFormat().getField("ghi"), ValueFactory.create("jkl"));
b2.setValue(b2.getFormat().getField("mno"), ValueFactory.create("pqr"));
assertEquals(binder.getColumn(b2, 1), ValueFactory.create("jkl"));
assertEquals(binder.getColumn(b2, 2), ValueFactory.create("pqr"));
assertEquals(binder.getColumn(b2, 0), ValueFactory.create("def"));
assertEquals(binder.getColumn(b2, 3), null);
}
示例5: testBundleColumnBinder2
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Test
public void testBundleColumnBinder2() {
Bundle b1 = new ListBundle();
BundleColumnBinder binder = new BundleColumnBinder(b1);
binder.appendColumn(b1, ValueFactory.create("abc"));
binder.appendColumn(b1, ValueFactory.create("def"));
binder.appendColumn(b1, ValueFactory.create("ghi"));
assertEquals(binder.getColumn(b1, 1), ValueFactory.create("def"));
assertEquals(binder.getColumn(b1, 2), ValueFactory.create("ghi"));
assertEquals(binder.getColumn(b1, 0), ValueFactory.create("abc"));
assertEquals(binder.getColumn(b1, 3), null);
Bundle b2 = new ListBundle((ListBundleFormat) b1.getFormat());
binder.appendColumn(b2, ValueFactory.create("abc"));
binder.appendColumn(b2, ValueFactory.create("def"));
binder.appendColumn(b2, ValueFactory.create("ghi"));
binder.appendColumn(b2, ValueFactory.create("jkl"));
assertEquals(binder.getColumn(b2, 1), ValueFactory.create("def"));
assertEquals(binder.getColumn(b2, 2), ValueFactory.create("ghi"));
assertEquals(binder.getColumn(b2, 0), ValueFactory.create("abc"));
assertEquals(binder.getColumn(b2, 3), ValueFactory.create("jkl"));
assertEquals(binder.getColumn(b2, 4), null);
}
示例6: write
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Override
public boolean write(Bundle row, OutputStream outputStream) throws IOException {
if (row == null) {
return false;
}
rowBuffer.add(row);
return maybeFlush(outputStream);
}
示例7: next
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Override
public Bundle next() {
if (bundleQueue.isEmpty()) {
readNextBlock();
}
return bundleQueue.poll();
}
示例8: getValue
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Override
public ValueObject getValue(Bundle bundle) {
if (bundle.getFormat() != lastFormat) {
lastFormat = bundle.getFormat();
lastField = lastFormat.getField(name);
}
return bundle.getValue(lastField);
}
示例9: BatchingDataChannelOutput
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
/**
* Constructor initializes a empty messsage list and starts a purge thread which runs
* every {@code maxTimeInMillis} and checks to see if the messages need to be purged
* from the queue.
*
* @param batchSize - the number of messages that the channel should queue before invoking sendBatch
* @param maxTimeInMillis - the maximum time in milliseconds a message can sit on the queue before
* being sent to the channel.
*/
public BatchingDataChannelOutput(int batchSize, long maxTimeInMillis) {
messageList = new ArrayList<Bundle>();
this.maxTimeInMillis = maxTimeInMillis;
this.batchSize = batchSize;
bufferPurgeExecutor = MoreExecutors.getExitingScheduledExecutorService(
new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("BatchingDataChannelOutputThread-%d").build()),
5000, TimeUnit.MILLISECONDS);
bufferPurgeExecutor.scheduleWithFixedDelay(new BatchSendRunner(), maxTimeInMillis, maxTimeInMillis, TimeUnit.MILLISECONDS);
}
示例10: send
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Override
public void send(Bundle bundle) throws DataChannelError {
sendLock.lock();
try {
if (!sinkUp) {
throw new RuntimeException("BatchingDataChannelOutput thinks the batch sink is down");
}
messageList.add(bundle);
if (messageList.size() % batchSize == 0) {
sendBatchAndClear(messageList);
}
} finally {
sendLock.unlock();
}
}
示例11: sendBatchAndClear
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
private void sendBatchAndClear(List<Bundle> messageList) {
sendLock.lock();
try {
send(messageList);
messageList.clear();
} catch (Exception e) {
sinkUp = false;
log.error("Sending to kafka failed, will not send until BatchSendRunner succeeds");
log.error(e.getMessage());
throw new RuntimeException(e);
} finally {
lastSendTime = JitterClock.globalTime();
sendLock.unlock();
}
}
示例12: DataTableListWrapper
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
public DataTableListWrapper(List<Bundle> list) {
final ListBundleFormat listFormat = new ListBundleFormat();
this.format = listFormat;
this.list = list;
this.factory = new BundleFactory() {
@Override
public Bundle createBundle() {
return new ListBundle(listFormat);
}
};
}
示例13: getValue
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Override public ValueObject getValue(Bundle bundle) {
ValueObject field = baseAutoField.getValue(bundle);
for (int i = 0; (field != null) && (i < subNames.length); i++) {
field = getSubField(field, subNames[i]);
}
return field;
}
示例14: getLastSubField
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
private ValueObject getLastSubField(Bundle bundle) {
ValueObject field = baseAutoField.getValue(bundle);
checkNotNull(field, "missing top level field {}", baseAutoField);
for (int i = 0; i < (subNames.length - 1); i++) {
field = getSubField(field, subNames[i]);
checkNotNull(field, "missing mid level container value {}", subNames[i]);
}
return field;
}
示例15: getValue
import com.addthis.bundle.core.Bundle; //导入依赖的package包/类
@Nullable @Override public T getValue(Bundle bundle) {
ValueObject valueObject = field.getValue(bundle);
if (valueObject == null) {
return null;
}
return Jackson.defaultMapper().convertValue(valueObject.asNative(), type);
}