/** * Actually run the connection - listen for I2CP messages and respond. This * is the main driver for this class, though it gets all its meat from the * {@link net.i2p.data.i2cp.I2CPMessageReader I2CPMessageReader} * */ public synchronized void startRunning() throws IOException { if (_dead || _reader != null) throw new IllegalStateException(); _reader = new I2CPMessageReader(new BufferedInputStream(_socket.getInputStream(), BUF_SIZE), createListener()); _writer = new ClientWriterRunner(_context, this); I2PThread t = new I2PThread(_writer); t.setName("I2CP Writer " + __id.incrementAndGet()); t.setDaemon(true); t.start(); _out = new BufferedOutputStream(_socket.getOutputStream()); _reader.startReading(); // TODO need a cleaner for unclaimed items in _messages, but we have no timestamps... }
/** * To be instantiated by the context. * Others should use context.simpleTimer() instead * @deprecated use SimpleTimer2 */ @Deprecated private SimpleTimer(I2PAppContext context, String name) { runn = new SimpleStore(true); _log = context.logManager().getLog(SimpleTimer.class); _events = new TreeMap<Long, TimedEvent>(); _eventTimes = new HashMap<TimedEvent, Long>(256); _readyEvents = new ArrayList<TimedEvent>(4); I2PThread runner = new I2PThread(new SimpleTimerRunner()); runner.setName(name); runner.setDaemon(true); runner.start(); long maxMemory = SystemVersion.getMaxMemory(); int threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024)))); for (int i = 1; i <= threads ; i++) { I2PThread executor = new I2PThread(new Executor(context, _log, _readyEvents, runn)); executor.setName(name + "Executor " + i + '/' + threads); executor.setDaemon(true); executor.start(); } context.addShutdownTask(new Shutdown()); }
aliceThread.setName("Alice"); aliceThread.start(); } catch (Exception e) {
/** * Run client in a new thread. * * @param clientName can be null * @param args can be null * @param threadGroup can be null * @param cl can be null * @since 0.7.13 */ public static void runClient(String className, String clientName, String args[], RouterContext ctx, Log log, ThreadGroup threadGroup, ClassLoader cl) { if (log.shouldLog(Log.INFO)) log.info("Loading up the client application " + clientName + ": " + className + " " + Arrays.toString(args)); I2PThread t; if (threadGroup != null) t = new I2PThread(threadGroup, new RunApp(className, clientName, args, ctx, log, cl)); else t = new I2PThread(new RunApp(className, clientName, args, ctx, log, cl)); if (clientName == null) clientName = className + " client"; t.setName(clientName); t.setDaemon(true); if (cl != null) t.setContextClassLoader(cl); t.start(); }