This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web | |
urls = ( | |
'/(.*)', 'hello' | |
) | |
app = web.application(urls, globals()) | |
class hello: | |
def GET(self, name): | |
if not name: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import User | |
class Category(models.Model): | |
parent = models.ForeignKey('self', null=True) | |
name = models.CharField(max_length=10) | |
def __unicode__(self): | |
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.apache.commons.lang.StringUtils; | |
import org.apache.commons.lang.Validate; | |
import org.apache.commons.lang.math.NumberUtils; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import static com.google.common.base.Preconditions.checkState; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderRegionalTopology { | |
public static void main(String[] args) throws Exception { | |
TopologyBuilder builder = new TopologyBuilder(); | |
builder.setSpout("orderSource", new OrderEnabledMockSpout(), 5); | |
builder.setBolt("regional", new RegionalStatisticsBolt(), 20) | |
.fieldsGrouping("orderSource", new Fields("IP")); | |
Config conf = new Config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LocalCluster cluster = new LocalCluster(); | |
cluster.submitTopology("regional", conf, builder.createTopology()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderEnabledMockSpout implements IRichSpout { | |
private final static String[] ipAddress = new String[] | |
{"10.13.43.154", "10.112.43.12", "10.13.45.123", "10.113.43.4"}; | |
private SpoutOutputCollector collector; | |
@Override | |
public boolean isDistributed() { | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { | |
outputFieldsDeclarer.declare(new Fields("IP", "BizOrderId")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final static String[] ipAddress = new String[] | |
{"10.13.43.154", "10.112.43.12", "10.13.45.123", "10.113.43.4"}; | |
public void nextTuple() { | |
Utils.sleep(4000); | |
final Random rand = new Random(); | |
collector.emit(new Values(ipAddress[rand.nextInt(ipAddress.length)], Math.abs(rand.nextLong()))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegionalStatisticsBolt implements IBasicBolt { | |
private Map<String, AtomicLong> regionalCounterMapping = new HashMap<String, AtomicLong>(); | |
@Override | |
public void prepare(Map map, TopologyContext topologyContext) { | |
//To change body of implemented methods use File | Settings | File Templates. | |
} | |
@Override |
OlderNewer