Changeset e522ffa for apps/ministreaming


Ignore:
Timestamp:
Jun 14, 2012 7:44:47 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
6c59028
Parents:
64221fb3
Message:
  • I2PTunnel:
    • More client options cleanups
    • Options changes now propagate to running socket managers and sessions, and through to the router
  • SocketManager?:
    • Simplify factory, use 4-arg constructor, make fields final, deprecate 0-arg constructor
    • Improve how options are updated
    • Javadocs
Location:
apps/ministreaming/java/src/net/i2p/client/streaming
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManager.java

    r64221fb3 re522ffa  
    3939    public void setAcceptTimeout(long ms);
    4040    public long getAcceptTimeout();
     41
     42    /**
     43     *  Update the options on a running socket manager.
     44     *  Parameters in the I2PSocketOptions interface may be changed directly
     45     *  with the setters; no need to use this method for those.
     46     *  This does NOT update the underlying I2CP or tunnel options; use getSession().updateOptions() for that.
     47     *  @param options as created from a call to buildOptions(properties), non-null
     48     */
    4149    public void setDefaultOptions(I2PSocketOptions options);
     50
     51    /**
     52     *  Current options, not a copy, setters may be used to make changes.
     53     */
    4254    public I2PSocketOptions getDefaultOptions();
     55
    4356    public I2PServerSocket getServerSocket();
    4457   
     58    /**
     59     *  Create a copy of the current options, to be used in a setDefaultOptions() call.
     60     */
    4561    public I2PSocketOptions buildOptions();
     62
     63    /**
     64     *  Create a modified copy of the current options, to be used in a setDefaultOptions() call.
     65     *  @param opts The new options, may be null
     66     */
    4667    public I2PSocketOptions buildOptions(Properties opts);
    4768
     
    103124    public void setName(String name);
    104125
     126    /**
     127     * Deprecated - Factory will initialize.
     128     * @throws UnsupportedOperationException always
     129     */
    105130    public void init(I2PAppContext context, I2PSession session, Properties opts, String name);
    106131   
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java

    r64221fb3 re522ffa  
    55import java.io.IOException;
    66import java.io.InputStream;
     7import java.lang.reflect.Constructor;
    78import java.util.Iterator;
    89import java.util.Properties;
     
    162163
    163164    private static I2PSocketManager createManager(I2PSession session, Properties opts, String name) {
    164         //if (false) {
    165             //I2PSocketManagerImpl mgr = new I2PSocketManagerImpl();
    166             //mgr.setSession(session);
    167             //mgr.setDefaultOptions(new I2PSocketOptions());
    168             //return mgr;
    169         //} else {
    170             String classname = opts.getProperty(PROP_MANAGER, DEFAULT_MANAGER);
    171             if (classname != null) {
    172                 try {
    173                     Class cls = Class.forName(classname);
    174                     Object obj = cls.newInstance();
    175                     if (obj instanceof I2PSocketManager) {
    176                         I2PSocketManager mgr = (I2PSocketManager)obj;
    177                         I2PAppContext context = I2PAppContext.getGlobalContext();
    178                         mgr.init(context, session, opts, name);
    179                         return mgr;
    180                     } else {
    181                         throw new IllegalStateException("Invalid manager class [" + classname + "]");
    182                     }
    183                 } catch (ClassNotFoundException cnfe) {
    184                     _log.error("Error loading " + classname, cnfe);
    185                     throw new IllegalStateException("Invalid manager class [" + classname + "] - not found");
    186                 } catch (InstantiationException ie) {
    187                     _log.error("Error loading " + classname, ie);
    188                     throw new IllegalStateException("Invalid manager class [" + classname + "] - unable to instantiate");
    189                 } catch (IllegalAccessException iae) {
    190                     _log.error("Error loading " + classname, iae);
    191                     throw new IllegalStateException("Invalid manager class [" + classname + "] - illegal access");
    192                 }
    193             } else {
    194                 throw new IllegalStateException("No manager class specified");
    195             }
    196         //}
    197        
     165        I2PAppContext context = I2PAppContext.getGlobalContext();
     166        String classname = opts.getProperty(PROP_MANAGER, DEFAULT_MANAGER);
     167        try {
     168            Class cls = Class.forName(classname);
     169            Constructor<I2PSocketManager> con = (Constructor<I2PSocketManager>)
     170                  cls.getConstructor(new Class[] {I2PAppContext.class, I2PSession.class, Properties.class, String.class});
     171            I2PSocketManager mgr = con.newInstance(new Object[] {context, session, opts, name});
     172            return mgr;
     173        } catch (Throwable t) {
     174            _log.log(Log.CRIT, "Error loading " + classname, t);
     175            throw new IllegalStateException(t);
     176        }
     177
    198178    }
    199179
Note: See TracChangeset for help on using the changeset viewer.