當前位置: 首頁>>代碼示例>>Java>>正文


Java Values類代碼示例

本文整理匯總了Java中org.apache.storm.tuple.Values的典型用法代碼示例。如果您正苦於以下問題:Java Values類的具體用法?Java Values怎麽用?Java Values使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Values類屬於org.apache.storm.tuple包,在下文中一共展示了Values類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deserialize

import org.apache.storm.tuple.Values; //導入依賴的package包/類
@Override
public List<Object> deserialize(ByteBuffer ser) {
    String jsonStr = null;
    if (ser.hasArray()) {
        int base = ser.arrayOffset();
        jsonStr = new String(ser.array(), base + ser.position(), ser.remaining());
    } else {
        jsonStr = new String(Utils.toByteArray(ser), UTF8_CHARSET);
    }
    JSONObject jsonObject = JSONObject.fromObject(jsonStr);
    Values values = new Values();
    for (String outputField : outputFields) {
        if("jsonBody".equals(outputField)) {
            values.add(jsonStr);
        } else {
            if(!jsonObject.containsKey(outputField)) {
                JSONObject rcMsgpara = JSONObject.fromObject(jsonObject.get("rc_msg_para"));
                values.add(rcMsgpara.get(outputField));
            } else {
                values.add(jsonObject.get(outputField));
            }
        }
    }
    return values;
}
 
開發者ID:JiuzhouSec,項目名稱:nightwatch,代碼行數:26,代碼來源:JSONScheme.java

示例2: nextTuple

import org.apache.storm.tuple.Values; //導入依賴的package包/類
public void nextTuple() {
	String sentence = sentences[index];
	
	System.out.println(sentence);
	
	this.collector.emit(new Values(sentence));
	index++;
	if (index >= sentences.length) {
		index = 0;
	}
	try {
		Thread.sleep(1);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:17,代碼來源:FixedSentenceSpout.java

示例3: main

import org.apache.storm.tuple.Values; //導入依賴的package包/類
public static void main(String[] args) {
	FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3,
			new Values("this is simple example of trident topology"), new Values(
					"this example count same words"));
	spout.setCycle(true);

	//TransactionalTridentKafkaSpout spout = new TransactionalTridentKafkaSpout(new TridentKafkaConfig(new ZkHosts("localhost:9091"), "test"));
	TridentTopology topology = new TridentTopology();
	MemoryMapState.Factory stateFactory = new MemoryMapState.Factory();
	topology
			.newStream("spout1", spout)
			.each(new Fields("sentence"), new Split(), new Fields("word"))
			.groupBy(new Fields("word")).persistentAggregate(stateFactory, new Count(),
					new Fields("count")).newValuesStream()
			.filter(new DisplayOutputFilter()).parallelismHint(6);
	
	Config config = new Config();
	config.setNumWorkers(3);
	LocalCluster cluster = new LocalCluster();
	cluster.submitTopology("storm-trident-example", config, topology.build());
}
 
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:22,代碼來源:BasicTridentTopology.java

示例4: execute

import org.apache.storm.tuple.Values; //導入依賴的package包/類
@Override
public void execute(Tuple tuple) {
  Object obj = tuple.getValue(0);
  long count = tuple.getLong(1);
  int source = tuple.getSourceTask();
  Map<Integer, Long> subCounts = counts.get(obj);
  if (subCounts == null) {
    subCounts = new HashMap<Integer, Long>();
    counts.put(obj, subCounts);
  }
  //Update the current count for this object
  subCounts.put(source, count);
  //Output the sum of all the known counts so for this key
  long sum = 0;
  for (Long val: subCounts.values()) {
    sum += val;
  }
  collector.emit(new Values(obj, sum));
}
 
開發者ID:Paleozoic,項目名稱:storm_spring_boot_demo,代碼行數:20,代碼來源:RollingCountAggBolt.java

示例5: handleException

import org.apache.storm.tuple.Values; //導入依賴的package包/類
private void handleException(String url, Throwable e, Metadata metadata,
        Tuple tuple, String errorSource, String errorMessage) {
    LOG.error(errorMessage);
    // send to status stream in case another component wants to update
    // its status
    metadata.setValue(Constants.STATUS_ERROR_SOURCE, errorSource);
    metadata.setValue(Constants.STATUS_ERROR_MESSAGE, errorMessage);
    collector.emit(StatusStreamName, tuple, new Values(url, metadata,
            Status.ERROR));
    collector.ack(tuple);
    // Increment metric that is context specific
    String s = "error_" + errorSource.replaceAll(" ", "_") + "_";
    eventCounter.scope(s + e.getClass().getSimpleName()).incrBy(1);
    // Increment general metric
    eventCounter.scope("parse exception").incrBy(1);
}
 
開發者ID:eorliac,項目名稱:patent-crawler,代碼行數:17,代碼來源:PatentParserBolt.java

示例6: testNegatingChain

import org.apache.storm.tuple.Values; //導入依賴的package包/類
/**
 * Test that each step of a chain is processed using a string.
 */
@Test
public void testNegatingChain() {
    final VirtualSpoutIdentifier consumerId = new DefaultVirtualSpoutIdentifier("FakeConsumer");

    final Message message1 = new Message(
        new MessageId("foobar", 1, 0L, consumerId),
        new Values(1)
    );

    final Message message2 = new Message(
        new MessageId("foobar", 1, 0L, consumerId),
        new Values(2)
    );

    final FilterChain filterChain = new FilterChain()
        .addStep(new DefaultFilterChainStepIdentifier("1"), new NegatingFilterChainStep(new NumberFilter(2)))
    ;

    assertTrue("Message 1 should be filtered", filterChain.filter(message1));

    assertFalse("Message 2 shouldn't be filtered", filterChain.filter(message2));
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:26,代碼來源:FilterChainTest.java

示例7: testDeserialize

import org.apache.storm.tuple.Values; //導入依賴的package包/類
/**
 * Silly test to go from String to byte[] to ByteBuffer to String.
 * Heh.
 */
@Test
public void testDeserialize() {
    @SuppressWarnings("checkstyle:AvoidEscapedUnicodeCharacters")
    final String value = "This Is My Text\uD83D\uDC7B";
    final byte[] valueBytes = value.getBytes(Charsets.UTF_8);

    // Pull implementation into a Deserializer obj.
    final Deserializer myScheme = new MyScheme();

    // Attempt to deserialize
    final Values myValues = myScheme.deserialize("TopicName", 2, 2222L, "Key".getBytes(Charsets.UTF_8), valueBytes);

    // Validate
    assertNotNull(myValues);
    assertEquals("Should have 1 entry", 1, myValues.size());
    assertEquals("Should be our value", value, myValues.get(0));
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:22,代碼來源:AbstractSchemeTest.java

示例8: testDeserializeWithEmptyByteArray

import org.apache.storm.tuple.Values; //導入依賴的package包/類
/**
 * Silly test to go from [] to [] to [] to "".
 * Heh.
 */
@Test
public void testDeserializeWithEmptyByteArray() {
    final byte[] inputNullBytes = new byte[0];

    // Pull implementation into a Deserializer obj.
    final Deserializer myScheme = new MyScheme();

    // Attempt to deserialize
    final Values myValues = myScheme.deserialize("TopicName", 2, 2222L, "Key".getBytes(Charsets.UTF_8), inputNullBytes);

    // Validate
    assertNotNull(myValues);
    assertEquals("Should have 1 entry", 1, myValues.size());
    assertEquals("Should be our value", "", myValues.get(0));
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:20,代碼來源:AbstractSchemeTest.java

示例9: handleCreateRequest

import org.apache.storm.tuple.Values; //導入依賴的package包/類
private void handleCreateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowCreateRequest) message.getData()).getPayload();

    ImmutablePair<PathInfoData, PathInfoData> path = pathComputer.getPath(requestedFlow);
    logger.info("Created flow path: {}", path);

    // TODO: Can we avoid special logic for "isOneSwitchFlow" .. make it the responsibility of the pathComputer?
    if (!flowCache.isOneSwitchFlow(requestedFlow) && pathComputer.isEmpty(path)) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(),
                ErrorType.CREATION_FAILURE, "Could not create flow", "Path was not found");
    }

    ImmutablePair<Flow, Flow> flow = flowCache.createFlow(requestedFlow, path);
    logger.info("Created flow: {}", flow);

    Values topology = new Values(Utils.MAPPER.writeValueAsString(
            new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.CREATE, message.getCorrelationId())));
    outputCollector.emit(StreamType.CREATE.toString(), tuple, topology);

    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)),
            message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:24,代碼來源:CrudBolt.java

示例10: testDeserializeReturnsNull

import org.apache.storm.tuple.Values; //導入依賴的package包/類
/**
 * If we return null, return null.
 */
@Test
public void testDeserializeReturnsNull() {
    // Create implementation, and force abstract implementation to return null.
    final MyScheme myScheme = new MyScheme();
    myScheme.setReturnNull(true);

    // Attempt to deserialize
    final Values myValues = myScheme.deserialize(
        "TopicName",
        2,
        2222L,
        "Key".getBytes(Charsets.UTF_8),
        "value".getBytes(Charsets.UTF_8)
    );

    // Validate
    assertNull("Should pass the null through", myValues);
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:22,代碼來源:AbstractSchemeTest.java

示例11: handleUpdateRequest

import org.apache.storm.tuple.Values; //導入依賴的package包/類
private void handleUpdateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowUpdateRequest) message.getData()).getPayload();

    ImmutablePair<PathInfoData, PathInfoData> path = pathComputer.getPath(requestedFlow);
    logger.info("Updated flow path: {}", path);

    if (!flowCache.isOneSwitchFlow(requestedFlow) && pathComputer.isEmpty(path)) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(),
                ErrorType.UPDATE_FAILURE, "Could not create flow", "Path was not found");
    }

    ImmutablePair<Flow, Flow> flow = flowCache.updateFlow(requestedFlow, path);
    logger.info("Updated flow: {}", flow);

    Values topology = new Values(Utils.MAPPER.writeValueAsString(
            new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.UPDATE, message.getCorrelationId())));
    outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);

    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)),
            message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:23,代碼來源:CrudBolt.java

示例12: execute

import org.apache.storm.tuple.Values; //導入依賴的package包/類
@Override
public void execute(Tuple input) {
    String request = input.getString(0);
    try {
        Message message = MAPPER.readValue(request, Message.class);
        if (message instanceof CommandMessage) {
            Values values = new Values(Utils.MAPPER.writeValueAsString(new InfoMessage(healthCheck,
                    System.currentTimeMillis(), message.getCorrelationId(), Destination.NORTHBOUND)));
            collector.emit(Topic.HEALTH_CHECK, input, values);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message: ", request, exception);
    } finally {
        collector.ack(input);
    }
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:17,代碼來源:HealthCheckBolt.java

示例13: doTick

import org.apache.storm.tuple.Values; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected void doTick(Tuple tuple) {
    // FIXME(dbogun): tick only once, because timePassed never reset
    if (timePassed == discoveryInterval) {
        Values values = getNetworkRequest();
        if (values != null) {
            outputCollector.emit(StreamType.TPE.toString(), tuple, values);
        } else {
            logger.error("Could not send network cache request");
        }
    }
    if (timePassed <= discoveryInterval) {
        timePassed += 1;
    }
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:19,代碼來源:CacheBolt.java

示例14: emitRerouteCommands

import org.apache.storm.tuple.Values; //導入依賴的package包/類
private void emitRerouteCommands(Set<ImmutablePair<Flow, Flow>> flows, Tuple tuple,
                                 String correlationId, FlowOperation operation) {
    String rerouteCorrelationId = String.format("%s-%s", correlationId, REROUTE.toString());

    for (ImmutablePair<Flow, Flow> flow : flows) {
        try {
            flow.getLeft().setState(FlowState.DOWN);
            flow.getRight().setState(FlowState.DOWN);
            FlowRerouteRequest request = new FlowRerouteRequest(flow.getLeft(), operation);

            Values values = new Values(Utils.MAPPER.writeValueAsString(new CommandMessage(
                    request, System.currentTimeMillis(), rerouteCorrelationId, Destination.WFM)));
            outputCollector.emit(StreamType.WFM_DUMP.toString(), tuple, values);

            logger.info("Flow {} reroute command message sent", flow.getLeft().getFlowId());
        } catch (JsonProcessingException exception) {
            logger.error("Could not format flow reroute request by flow={}", flow, exception);
        }
    }
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:21,代碼來源:CacheBolt.java

示例15: handlePortEvent

import org.apache.storm.tuple.Values; //導入依賴的package包/類
private void handlePortEvent(Tuple tuple, PortInfoData portData) {
    String switchID = portData.getSwitchId();
    String portID = "" + portData.getPortNo();
    String updown = "" + portData.getState();
    logger.info("DISCO: Port Event: switch={} port={} state={}", switchID, portID, updown);

    if (isPortUpOrCached(updown)) {
        discovery.handlePortUp(switchID, portID);
    } else if (updown.equals(OFEMessageUtils.PORT_DOWN)) {
        discovery.handlePortDown(switchID, portID);
    } else {
        // TODO: Should this be a warning? Evaluate whether any other state needs to be handled
        logger.warn("PORT Event: ignoring state: {}", updown);
    }

    // Pass the original message along, to the Topology Engine topic.
    String json = tuple.getString(0);
    collector.emit(topoEngTopic, tuple, new Values(PAYLOAD, json));
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:20,代碼來源:OFELinkBolt.java


注:本文中的org.apache.storm.tuple.Values類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。