static BloomFilter<String> readBloomFilterFromfile(String bloomFilterFilePath) throws IOException { Funnel<String> memberFunnel = new Funnel<String>() { public void funnel(String memberId, PrimitiveSink sink) { sink.putString(memberId, Charsets.UTF_8); } }; try { FileInputStream fis = new FileInputStream(new File(bloomFilterFilePath)); return BloomFilter.readFrom(fis, memberFunnel); } catch(Exception e) { e.printStackTrace(); } return null; }
@Override public void funnel(StatisticParameters o, PrimitiveSink into) { into .putUnencodedChars(o.getClass().getCanonicalName()) .putChar(':') .putUnencodedChars(Strings.nullToEmpty(o.lang)) .putFloat(o.quantile) .putInt(o.duration) .putUnencodedChars(Strings.nullToEmpty(o.type)) .putInt(o.maxDevices) .putUnencodedChars(Strings.nullToEmpty(o.networkTypeGroup)) .putDouble(o.accuracy) .putUnencodedChars(Strings.nullToEmpty(o.country)) .putBoolean(o.userServerSelection) .putInt((endDate == null) ? 0 : (int) endDate.getTime()) .putInt(o.province); }
private BloomFilter<Seed> getOrCreate(String segment) { BloomFilter<Seed> seedBloomFilter = bloomFilters.get(segment); if (seedBloomFilter != null) { return seedBloomFilter; } synchronized (segment.intern()) { seedBloomFilter = bloomFilters.get(segment); if (seedBloomFilter != null) { return seedBloomFilter; } long expectedNumber = NumberUtils.toLong(VSCrawlerContext.vsCrawlerConfigFileWatcher.loadedProperties() .getProperty(VSCrawlerConstant.VSCRAWLER_SEED_MANAGER_EXPECTED_SEED_NUMBER), 1000000L); // any way, build a filter instance if not exist seedBloomFilter = BloomFilter.create(new Funnel<Seed>() { @Override public void funnel(Seed from, PrimitiveSink into) { into.putString(seedKeyResolver.resolveSeedKey(from), Charset.defaultCharset()); } }, expectedNumber); bloomFilters.put(segment, seedBloomFilter); } return seedBloomFilter; }
@Test public void ensureGeneric() { class SuperClass { } class SubClass extends SuperClass { } CuckooFilter<SuperClass> filter = CuckooFilter.create( new Funnel<SuperClass>() { public void funnel(SuperClass from, PrimitiveSink into) { into.putInt(from.hashCode()); } }, 1000, 0.03D); assertTrue(filter.add(new SuperClass())); assertTrue(filter.add(new SubClass())); }
GrowthTracker( final SerializableFunction<OutputT, KeyT> keyFn, final Coder<KeyT> outputKeyCoder, GrowthState<OutputT, KeyT, TerminationStateT> state, Growth.TerminationCondition<?, TerminationStateT> terminationCondition) { this.coderFunnel = new Funnel<OutputT>() { @Override public void funnel(OutputT from, PrimitiveSink into) { try { // Rather than hashing the output itself, hash the output key. KeyT outputKey = keyFn.apply(from); outputKeyCoder.encode(outputKey, Funnels.asOutputStream(into)); } catch (IOException e) { throw new RuntimeException(e); } } }; this.terminationCondition = terminationCondition; this.state = state; this.isOutputComplete = state.isOutputComplete; this.pollWatermark = state.pollWatermark; this.terminationState = state.terminationState; this.pending = Lists.newLinkedList(state.pending); }
@Override public void funnel(OFFlowRemovedVer14 message, PrimitiveSink sink) { // fixed value property version = 5 sink.putByte((byte) 0x5); // fixed value property type = 11 sink.putByte((byte) 0xb); // FIXME: skip funnel of length sink.putLong(message.xid); message.cookie.putTo(sink); sink.putInt(message.priority); sink.putShort(message.reason); message.tableId.putTo(sink); sink.putLong(message.durationSec); sink.putLong(message.durationNsec); sink.putInt(message.idleTimeout); sink.putInt(message.hardTimeout); message.packetCount.putTo(sink); message.byteCount.putTo(sink); message.match.putTo(sink); }
@Override public void funnel(OFPortModVer12 message, PrimitiveSink sink) { // fixed value property version = 3 sink.putByte((byte) 0x3); // fixed value property type = 16 sink.putByte((byte) 0x10); // fixed value property length = 40 sink.putShort((short) 0x28); sink.putLong(message.xid); message.portNo.putTo(sink); // skip pad (4 bytes) message.hwAddr.putTo(sink); // skip pad (2 bytes) sink.putLong(message.config); sink.putLong(message.mask); sink.putLong(message.advertise); // skip pad (4 bytes) }
@Override public void funnel(OFBsnGentableEntryStatsReplyVer14 message, PrimitiveSink sink) { // fixed value property version = 5 sink.putByte((byte) 0x5); // fixed value property type = 19 sink.putByte((byte) 0x13); // FIXME: skip funnel of length sink.putLong(message.xid); // fixed value property statsType = 65535 sink.putShort((short) 0xffff); OFStatsReplyFlagsSerializerVer14.putTo(message.flags, sink); // skip pad (4 bytes) // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x3L sink.putInt(0x3); FunnelUtils.putList(message.entries, sink); }
@Override public void funnel(OFBsnGetMirroringReplyVer11 message, PrimitiveSink sink) { // fixed value property version = 2 sink.putByte((byte) 0x2); // fixed value property type = 4 sink.putByte((byte) 0x4); // fixed value property length = 20 sink.putShort((short) 0x14); sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x5L sink.putInt(0x5); sink.putShort(message.reportMirrorPorts); // skip pad (3 bytes) }
@Override public void funnel(OFFeaturesReplyVer14 message, PrimitiveSink sink) { // fixed value property version = 5 sink.putByte((byte) 0x5); // fixed value property type = 6 sink.putByte((byte) 0x6); // fixed value property length = 32 sink.putShort((short) 0x20); sink.putLong(message.xid); message.datapathId.putTo(sink); sink.putLong(message.nBuffers); sink.putShort(message.nTables); message.auxiliaryId.putTo(sink); // skip pad (2 bytes) OFCapabilitiesSerializerVer14.putTo(message.capabilities, sink); sink.putLong(message.reserved); }
@Override public void funnel(OFBsnBwEnableSetReplyVer12 message, PrimitiveSink sink) { // fixed value property version = 3 sink.putByte((byte) 0x3); // fixed value property type = 4 sink.putByte((byte) 0x4); // fixed value property length = 24 sink.putShort((short) 0x18); sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x17L sink.putInt(0x17); sink.putLong(message.enable); sink.putLong(message.status); }
@Override public void funnel(OFFlowRemovedVer13 message, PrimitiveSink sink) { // fixed value property version = 4 sink.putByte((byte) 0x4); // fixed value property type = 11 sink.putByte((byte) 0xb); // FIXME: skip funnel of length sink.putLong(message.xid); message.cookie.putTo(sink); sink.putInt(message.priority); sink.putShort(message.reason); message.tableId.putTo(sink); sink.putLong(message.durationSec); sink.putLong(message.durationNsec); sink.putInt(message.idleTimeout); sink.putInt(message.hardTimeout); message.packetCount.putTo(sink); message.byteCount.putTo(sink); message.match.putTo(sink); }
@Override public void funnel(OFBsnVirtualPortCreateReplyVer12 message, PrimitiveSink sink) { // fixed value property version = 3 sink.putByte((byte) 0x3); // fixed value property type = 4 sink.putByte((byte) 0x4); // fixed value property length = 24 sink.putShort((short) 0x18); sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x10L sink.putInt(0x10); sink.putLong(message.status); sink.putLong(message.vportNo); }
@Override public void funnel(OFBsnGetMirroringReplyVer10 message, PrimitiveSink sink) { // fixed value property version = 1 sink.putByte((byte) 0x1); // fixed value property type = 4 sink.putByte((byte) 0x4); // fixed value property length = 20 sink.putShort((short) 0x14); sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x5L sink.putInt(0x5); sink.putShort(message.reportMirrorPorts); // skip pad (3 bytes) }
@Override public void funnel(OFBsnLacpStatsEntryVer13 message, PrimitiveSink sink) { message.portNo.putTo(sink); sink.putInt(message.actorSysPriority); message.actorSysMac.putTo(sink); sink.putInt(message.actorPortPriority); sink.putInt(message.actorPortNum); sink.putInt(message.actorKey); sink.putShort(message.convergenceStatus); // skip pad (1 bytes) sink.putInt(message.partnerSysPriority); message.partnerSysMac.putTo(sink); sink.putInt(message.partnerPortPriority); sink.putInt(message.partnerPortNum); sink.putInt(message.partnerKey); // skip pad (2 bytes) }
@Override public void funnel(OFAggregateStatsReplyVer13 message, PrimitiveSink sink) { // fixed value property version = 4 sink.putByte((byte) 0x4); // fixed value property type = 19 sink.putByte((byte) 0x13); // fixed value property length = 40 sink.putShort((short) 0x28); sink.putLong(message.xid); // fixed value property statsType = 2 sink.putShort((short) 0x2); OFStatsReplyFlagsSerializerVer13.putTo(message.flags, sink); // skip pad (4 bytes) message.packetCount.putTo(sink); message.byteCount.putTo(sink); sink.putLong(message.flowCount); // skip pad (4 bytes) }
@Override public void funnel(OFBsnFlowIdleVer14 message, PrimitiveSink sink) { // fixed value property version = 5 sink.putByte((byte) 0x5); // fixed value property type = 4 sink.putByte((byte) 0x4); // FIXME: skip funnel of length sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x28L sink.putInt(0x28); message.cookie.putTo(sink); sink.putInt(message.priority); message.tableId.putTo(sink); // skip pad (5 bytes) message.match.putTo(sink); }
@Override public void funnel(TileParameters o, PrimitiveSink into) { super.funnel(o, into); if (o instanceof PointTileParameters) { final PointTileParameters _o = (PointTileParameters) o; into .putDouble(_o.pointDiameter) .putBoolean(_o.noFill) .putBoolean(_o.noColor); if (highlight != null) into.putUnencodedChars(highlight.toString()); } }
@Override public void funnel(Path o, PrimitiveSink into) { into .putInt(o.zoom) .putInt(o.x) .putInt(o.y); }
@Override public void funnel(Entry<String, String> o, PrimitiveSink into) { into .putUnencodedChars(o.getKey()) .putChar(':') .putUnencodedChars(Strings.nullToEmpty(o.getValue())); }
@Override public void funnel(TileParameters o, PrimitiveSink into) { into .putUnencodedChars(o.getClass().getCanonicalName()) .putInt(o.size) .putUnencodedChars(o.mapOption) .putFloat(o.quantile) .putDouble(o.transparency) .putUnencodedChars(Strings.nullToEmpty(o.developerCode)); o.path.funnel(o.path, into); FILTER_MAP_FUNNEL.funnel(o.filterMap.entrySet(), into); }
@Override public void funnel(OFBucketVer14 message, PrimitiveSink sink) { // FIXME: skip funnel of length sink.putInt(message.weight); message.watchPort.putTo(sink); message.watchGroup.putTo(sink); // skip pad (4 bytes) FunnelUtils.putList(message.actions, sink); }
@Override public void funnel(OFMeterFeaturesStatsReplyVer13 message, PrimitiveSink sink) { // fixed value property version = 4 sink.putByte((byte) 0x4); // fixed value property type = 19 sink.putByte((byte) 0x13); // fixed value property length = 32 sink.putShort((short) 0x20); sink.putLong(message.xid); // fixed value property statsType = 11 sink.putShort((short) 0xb); OFStatsReplyFlagsSerializerVer13.putTo(message.flags, sink); // skip pad (4 bytes) message.features.putTo(sink); }
@Override public void funnel(OFPortStatsReplyVer10 message, PrimitiveSink sink) { // fixed value property version = 1 sink.putByte((byte) 0x1); // fixed value property type = 17 sink.putByte((byte) 0x11); // FIXME: skip funnel of length sink.putLong(message.xid); // fixed value property statsType = 4 sink.putShort((short) 0x4); OFStatsReplyFlagsSerializerVer10.putTo(message.flags, sink); FunnelUtils.putList(message.entries, sink); }
@Override public void funnel(OFBsnTlvTxPacketsVer13 message, PrimitiveSink sink) { // fixed value property type = 0x3 sink.putShort((short) 0x3); // fixed value property length = 12 sink.putShort((short) 0xc); message.value.putTo(sink); }
@Override public void funnel(OFOxmBsnVrfMaskedVer14 message, PrimitiveSink sink) { // fixed value property typeLen = 0x30508L sink.putInt(0x30508); message.value.putTo(sink); message.mask.putTo(sink); }
@Override public void funnel(OFActionGroupVer13 message, PrimitiveSink sink) { // fixed value property type = 22 sink.putShort((short) 0x16); // fixed value property length = 8 sink.putShort((short) 0x8); message.group.putTo(sink); }
@Override public void funnel(OFBsnGetInterfacesRequestVer12 message, PrimitiveSink sink) { // fixed value property version = 3 sink.putByte((byte) 0x3); // fixed value property type = 4 sink.putByte((byte) 0x4); // fixed value property length = 16 sink.putShort((short) 0x10); sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x9L sink.putInt(0x9); }
@Override public void funnel(OFBsnVirtualPortCreateRequestVer14 message, PrimitiveSink sink) { // fixed value property version = 5 sink.putByte((byte) 0x5); // fixed value property type = 4 sink.putByte((byte) 0x4); // FIXME: skip funnel of length sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0xfL sink.putInt(0xf); message.vport.putTo(sink); }
@Override public void funnel(OFMeterFeaturesStatsReplyVer14 message, PrimitiveSink sink) { // fixed value property version = 5 sink.putByte((byte) 0x5); // fixed value property type = 19 sink.putByte((byte) 0x13); // fixed value property length = 32 sink.putShort((short) 0x20); sink.putLong(message.xid); // fixed value property statsType = 11 sink.putShort((short) 0xb); OFStatsReplyFlagsSerializerVer14.putTo(message.flags, sink); // skip pad (4 bytes) message.features.putTo(sink); }
@Override public void funnel(OFHelloVer13 message, PrimitiveSink sink) { // fixed value property version = 4 sink.putByte((byte) 0x4); // fixed value property type = 0 sink.putByte((byte) 0x0); // FIXME: skip funnel of length sink.putLong(message.xid); FunnelUtils.putList(message.elements, sink); }
@Override public void funnel(OFGroupFeaturesStatsRequestVer12 message, PrimitiveSink sink) { // fixed value property version = 3 sink.putByte((byte) 0x3); // fixed value property type = 18 sink.putByte((byte) 0x12); // fixed value property length = 16 sink.putShort((short) 0x10); sink.putLong(message.xid); // fixed value property statsType = 8 sink.putShort((short) 0x8); OFStatsRequestFlagsSerializerVer12.putTo(message.flags, sink); // skip pad (4 bytes) }
@Override public void funnel(OFQueuePropMinRateVer12 message, PrimitiveSink sink) { // fixed value property type = 0x1 sink.putShort((short) 0x1); // fixed value property length = 16 sink.putShort((short) 0x10); // skip pad (4 bytes) sink.putInt(message.rate); // skip pad (6 bytes) }
@Override public void funnel(OFActionPopMplsVer14 message, PrimitiveSink sink) { // fixed value property type = 20 sink.putShort((short) 0x14); // fixed value property length = 8 sink.putShort((short) 0x8); message.ethertype.putTo(sink); // skip pad (2 bytes) }
@Override public void funnel(OFGroupDescStatsReplyVer13 message, PrimitiveSink sink) { // fixed value property version = 4 sink.putByte((byte) 0x4); // fixed value property type = 19 sink.putByte((byte) 0x13); // FIXME: skip funnel of length sink.putLong(message.xid); // fixed value property statsType = 7 sink.putShort((short) 0x7); OFStatsReplyFlagsSerializerVer13.putTo(message.flags, sink); // skip pad (4 bytes) FunnelUtils.putList(message.entries, sink); }
@Override public void funnel(OFBsnVirtualPortRemoveReplyVer12 message, PrimitiveSink sink) { // fixed value property version = 3 sink.putByte((byte) 0x3); // fixed value property type = 4 sink.putByte((byte) 0x4); // fixed value property length = 20 sink.putShort((short) 0x14); sink.putLong(message.xid); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x1aL sink.putInt(0x1a); sink.putLong(message.status); }
@Override public void funnel(OFOxmEthSrcMaskedVer14 message, PrimitiveSink sink) { // fixed value property typeLen = 0x8000090cL sink.putInt((int) 0x8000090c); message.value.putTo(sink); message.mask.putTo(sink); }
@Override public void funnel(OFActionBsnSetTunnelDstVer11 message, PrimitiveSink sink) { // fixed value property type = 65535 sink.putShort((short) 0xffff); // fixed value property length = 16 sink.putShort((short) 0x10); // fixed value property experimenter = 0x5c16c7L sink.putInt(0x5c16c7); // fixed value property subtype = 0x2L sink.putInt(0x2); sink.putLong(message.dst); }
@Override public void funnel(OFOxmBsnUdf0MaskedVer12 message, PrimitiveSink sink) { // fixed value property typeLen = 0x31108L sink.putInt(0x31108); message.value.putTo(sink); message.mask.putTo(sink); }