执行com.taobao.timetunnel.bootstrap.BrokerBootstrap 的main方法报错
Starting a reliable broker.
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.3.2-1031432, built on 11/05/2010 05:32 GMT
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:host.name=2S4PKZGC5RFRU9Z
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_07
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.home=C:\Program Files (x86)\Java\jre7
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.class.path=F:\workspace\timetunnel\bin;E:\TimeTunnel\apps\dfswriter\lib\commons-io-1.4.jar;E:\TimeTunnel\apps\dfswriter\lib\commons-pool-1.4.jar;E:\TimeTunnel\apps\dfswriter\lib\FilterApi.jar;E:\TimeTunnel\apps\dfswriter\lib\hadoop-0.19.2-core.jar;E:\TimeTunnel\apps\dfswriter\lib\hadoop-0.20.2-core.jar;E:\TimeTunnel\apps\dfswriter\lib\hbase-0.90.3.jar;E:\TimeTunnel\apps\dfswriter\lib\libthrift-0.5.0-20100116.jar;E:\TimeTunnel\apps\dfswriter\lib\libthrift-0.7.0.jar;E:\TimeTunnel\apps\dfswriter\lib\quartz-all-1.8.3.jar;E:\TimeTunnel\apps\dfswriter\lib\TTClient.jar;E:\TimeTunnel\apps\dfswriter\lib\zookeeper-3.3.2.jar;E:\TimeTunnel\apps\savefile\lib\libthrift-0.5.0-20100116.jar;E:\TimeTunnel\apps\savefile\lib\quartz-all-1.8.3.jar;E:\TimeTunnel\idl\lib\javax.jms_1.1.0.jar;E:\TimeTunnel\idl\lib\jmxri-1.2.1.jar;E:\TimeTunnel\idl\lib\jmxtools-1.2.1.jar;E:\TimeTunnel\idl\lib\libthrift-0.5.0-20100116.jar;E:\TimeTunnel\router\lib\libthrift-0.5.0.jar;E:\TimeTunnel\router\lib\timetunnel2-cluster-0.1.0.jar;E:\TimeTunnel\router\lib\zk-recipes.jar;E:\TimeTunnel\router\lib\zookeeper-3.2.2.jar;E:\eclipselib\junit-4.11.jar;E:\eclipselib\zookeeper-3.3.5.jar;E:\eclipse\plugins\org.apache.log4j_1.2.15.v201012070815.jar;E:\eclipselib\google-gson-2.2.2\gson-2.2.2.jar;E:\eclipselib\commons-cli-1.2.jar;E:\eclipselib\commons-lang-2.5.jar;E:\eclipselib\commons-codec-1.6.jar
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.library.path=C:\Program Files (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows7Master;E:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Java\jdk1.7.0_07/bin;C:\Program Files (x86)\Java\jdk1.7.0_07/jre/bin;D:\apache-ant-1.8.4\bin;$ANT_HOME\bin;$HADOOP_HOME\bin;E:\eclipse;;.
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 7
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:os.arch=x86
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:os.version=6.1
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:user.name=Administrator
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\Administrator
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Client environment:user.dir=F:\workspace\timetunnel
12/12/07 14:40:59 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=192.168.15.36:2181 sessionTimeout=10000 watcher=com.taobao.timetunnel.zookeeper.ZooKeeperConnector@132b73b
12/12/07 14:40:59 INFO zookeeper.ClientCnxn: Opening socket connection to server /192.168.15.36:2181
12/12/07 14:41:09 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused: no further information
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
	at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)
12/12/07 14:41:10 INFO zookeeper.ClientCnxn: Opening socket connection to server 192.168.15.36/192.168.15.36:2181
12/12/07 14:41:11 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused: no further information
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
	at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)
12/12/07 14:41:13 INFO zookeeper.ClientCnxn: Opening socket connection to server 192.168.15.36/192.168.15.36:2181
12/12/07 14:41:14 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused: no further information
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
	at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)


com.taobao.timetunnel.bootstrap.BrokerBootstrap代码

package com.taobao.timetunnel.bootstrap;

import static java.net.InetAddress.getLocalHost;

import java.io.File;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;

import com.taobao.timetunnel.broker.EfficientThriftBroker;
import com.taobao.timetunnel.broker.ReliableThriftBroker;
import com.taobao.timetunnel.broker.ThriftBroker;
import com.taobao.timetunnel.center.Center;
import com.taobao.timetunnel.center.ZookeeperCenter;
import com.taobao.util.MemoryMonitor;
import com.taobao.util.PropertiesHelper;
import com.taobao.util.SizeConverter;
import com.taobao.util.PropertiesHelper.Converter;

/**
 * {@link BrokerBootstrap}
 * 
 * @author <a href=mailto:jushi@taobao.com>jushi</a>
 * @created 2010-11-18
 * 
 */
public class BrokerBootstrap {

  /**
   * @param args
   */
  public static void main(final String[] args) {
    String conf = "conf.properties";
    if (args.length == 1) conf = args[0];

    try {
      final ThriftBroker<ByteBuffer> thriftBroker =
        createThriftBrokerWith(new PropertiesHelper(new File(conf)));
      addShutdownHook(thriftBroker);
      Thread.currentThread().setName("reliable-broker");
      thriftBroker.start();
    } catch (final Exception e) {
      printUsageAndExit(new File(conf), e);
    }
  }

  private static void addShutdownHook(final ThriftBroker<ByteBuffer> thriftBroker) {
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

      @Override
      public void run() {
        thriftBroker.stop();
      }
    }, "shutdown-broker-hook"));
  }

  private static Center createCenterWith(final PropertiesHelper helper) {
    return new ZookeeperCenter(helper.getString("zookeeper.connectString"),
                               helper.getInt("zookeeper.sessionTimeout"));
  }

  private static MemoryMonitor createMonitorWith(final PropertiesHelper helper) {
    final long max = MemoryMonitor.max() / 100;
    final long shortage = max * helper.getInt("memory.shortageRatio", 45);
    final long abundant = max * helper.getInt("memory.abundantRatio", 75);
    return new MemoryMonitor(shortage, abundant);
  }

  private static Converter<Integer> sizeConverter = new SizeConverter();

  private static ThriftBroker<ByteBuffer> createThriftBrokerWith(final PropertiesHelper helper) throws UnknownHostException {
    final File data = new File(helper.getString("broker.home", "."), "data");//创建以"broker.home"对应路径下的data文件
    data.mkdirs();

    final Center center = createCenterWith(helper);
    final MemoryMonitor monitor = createMonitorWith(helper);

    ThriftBroker<ByteBuffer> thriftBroker = null;
    final String host = helper.getString("broker.host", getLocalHost().getHostName());
    final int port = helper.getInt("external.port");
    final String group = helper.getString("broker.group");
    final int syncPoint = helper.getInt("group.syncPoint", 200);
    final int maxMessageSize = helper.get(sizeConverter, "broker.maxMessageSize", "4K");

    int chunkCapacity = helper.get(sizeConverter, "chunk.capacity", "64M");
    int chunkBuffer = helper.get(sizeConverter, "chunk.buffer", "32K");
    if (helper.contains("internal.port")) {
      thriftBroker =
        new ReliableThriftBroker(center,
                                 host,
                                 port,
                                 helper.getInt("internal.port"),
                                 group,
                                 syncPoint,
                                 maxMessageSize,
                                 chunkCapacity,
                                 chunkBuffer,
                                 monitor,
                                 data);
      System.out.println("Starting a reliable broker.");
    } else {
      thriftBroker =
        new EfficientThriftBroker(center,
                                  host,
                                  port,
                                  group,
                                  syncPoint,
                                  monitor,
                                  data,
                                  maxMessageSize,
                                  chunkCapacity,
                                  chunkBuffer);
      System.out.println("Starting a efficient broker.");
    }
    thriftBroker.setMaxReadBufferBytes(helper.getInt("broker.maxReadBufferBytes", Integer.MAX_VALUE));
    thriftBroker.setWorkThread(helper.getInt("broker.workThread", 5));
    return thriftBroker;
  }

  private static void printUsageAndExit(final File file, final Exception e) {
    e.printStackTrace();
    System.err.println("Invalid conf file path, please check your conf file " + file);
    System.err.println("Usage : CMD [conf file path]");
    System.exit(-1);
  }

}


conf.propertites

# broker的home路径, 默认为当前目录, broker产生持久化数据会存在这个目录下
broker.home = /usr/local/timetunnel/broker/target
# broker组, 分组以便分级服务.
broker.group = group1
# 设置broker对外服务(订阅发布)的端口
external.port = 9999
# 设置broker对内服务(数据可靠同步)的端口, 不设置则broker依旧可以单点运行 
internal.port = 9998
# zookeeper是broker集群的协调者, 必须配置器连接地址和端口, eg : 192.168.1.132:33561,192.168.1.133:33561/root
zookeeper.connectString =192.168.15.36:2181
# 连接zookeeper会话超时时间, 单位毫秒, 它应该是zookeeper服务器配置的tickTime的2~20倍 
zookeeper.sessionTimeout = 10000
# broker的主机名, 也可以是ip, 系统会自动取, 一般无需配置
broker.host = 192.168.15.36
######################## 以上是启动必选配置项 ######################### 
######################## 以下是调优可选配置项 #########################
# 一个订阅通常一组client来获取, 为保证每个client获取的数量近乎平均, 就需要在累计一定数量时进行同步, 这个同步点默认为200 
# group.syncPoint = 200
# 为避免内存溢出, broker会根据内存的消耗情况, 将部分数据交换到磁盘文件中, 内存中保存其数据的索引
# 当内存短缺时开始交换, 直到内存充裕, 下面是分别配置短缺和充裕的内存比例值, 最大为99, 最小为1.
# 内存短缺比例默认为45
# memory.shortageRatio = 45
# 内存充裕比例默认为75
# memory.abundantRatio = 75
# 设置broker中thrift server服务的线程数, 默认是5, 可以根据应用要求适当调整
# broker.workThread = 5
# 设置broker中thrift server最大读取内存数, 默认为2的31次方, 一般情况下无需修改 
# broker.maxReadBufferBytes = 
# 设置broker中单个消息的最大值, 默认为4K, 单位可以是K或M
# broker.maxMessageSize = 4K
# 内存交换磁盘的文件大小, 默认64M, 单位可以是K或M
# chunk.capacity = 64M 
# 内存交换磁盘的文件缓存, 默认32K, 单位可以是K或M
# chunk.buffer = 32K


 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐