Package de.desy.tine.startup

Source Code of de.desy.tine.startup.DefaultTInitializerFactory$DefaultTInitializer$IpNameHndlr

package de.desy.tine.startup;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Properties;
import java.util.logging.FileHandler;

import de.desy.tine.csvUtils.csv;
import de.desy.tine.csvUtils.csvColumn;
import de.desy.tine.csvUtils.csvHandler;
import de.desy.tine.definitions.TErrorList;
import de.desy.tine.server.logger.MsgLog;
import de.desy.tine.server.logger.TFecLog;

public class DefaultTInitializerFactory extends TInitializerFactory
{
  private static String srvOs = "JAVA";
  private static int srvMajor = 4;
  private static int srvMinor = 3;
  private static int srvRevision = 12;
  private static int buildId = 5062;
  private static String ENS = "131.169.120.41";
  private static final int SRV_PORT = 9003;
  private static final int TCP_PORT = 8503;
  private static final int STREAM_PORT = 10003;
  private static final int PIPE_PORT = 10503;
  private static String GCAST = "238.1.1.0";
  private static final int GCAST_PORT = 8004;
  private static String MCAST = "238.1.1.1";
  private static final int MCAST_PORT = 9503;
  private static final String NETCAST = "238.1.1.2";
  private static final int NETCAST_PORT = 9002;
  private static final int UDP_CLN_PORT = 8050;
  private static int srvRcvBufferSize = 0x10000;
  private static int clnRcvBufferSize = 0x10000;
  private static int srvSndBufferSize = 0x2000;
  private static int clnSndBufferSize = 0x2000;
  private static int sckTimeToLive = 16;
  private static int srvPacketMtu = 1472;
  private static DefaultTInitializer instance = null;
  private static String srvStartup = "unknown";
  private static String srvCwd = "unknown";
  private static int pid = 0;
  private static boolean isRichClient = true;
  private class DefaultTInitializer implements TInitializer
  {
    private String tineCache = null;
    private String tineHome = null;
    private String fecHome = null;
    private String historyHome = null;
    private String logHome = null;
    private String addrFileLocation = null;
    private String eqpFileLocation = null;
    private String cshostsFileLocation = null;
    private String fecidFileLocation = null;
    private String exportsFileLocation = null;
    private String usersFileLocation = null;
    private String grpsFileLocation = null;
    private String aliasFileLocation = null;
    private String netsFileLocation = null;
    private String alarmwFileLocation = null;
    private String historyFileLocation = null;
    private String logFileLocation = null;
    private String myipFileLocation = null;
    private Properties tineProperties = new Properties();
    public DefaultTInitializer()
    {
      initialize();
    }
    private boolean hasInitialzed = false;
    private synchronized void initialize()
    {
      if (hasInitialzed) return;
      try
      { // try to force IPv4
        System.setProperty("java.net.preferIPv4Stack", "true");
      }
      catch (Exception e)
      {
        System.out.println("could not set IPv4 preference : "+e.getMessage());
      }
      // Read properties file.
      try
      { // a DESY site special case ...
        InetAddress host = InetAddress.getLocalHost();
        if (!host.getHostAddress().startsWith("131.169."))
        { // clear this (can then be overwritten explicitly)
          ENS = null;
        }
      }
      catch (Exception e)
      { // don't even try to figure out why ...
        ENS = null;
      }
      try
      {
        String cp = System.getProperty("java.class.path");
        String cpSeparator = System.getProperty("path.separator");
        String[] cplibs = cp.split(cpSeparator);
        String jarHome = null;
        int stopindex = -1;
        boolean found = false;
        for (int i = 0; i < cplibs.length; i++)
        {
          if ((stopindex = cplibs[i].indexOf("tine.jar")) > 0)
          {
            jarHome = cplibs[i].substring(0, stopindex - 1);
            break;
          }
        }
        if (stopindex == -1) jarHome = ".";
        String prpsFileName = jarHome+File.separator+"tine.properties";
        if (!(new File(prpsFileName).exists()))
        { // simple check on this directory didn't find anything
          prpsFileName = System.getProperty("user.dir")+File.separator+"tine.properties";
        }
        else
        {
          MsgLog.log("initializer","found tine.properties on the class path",0,null,1);
          found = true;
        }
        if (!found)
        {
          if (!(new File(prpsFileName).exists()))
          { // simple check on home directory didn't find anything
            prpsFileName = System.getProperty("java.ext.dirs")+File.separator+"tine.properties";
          }
          else
          {
            MsgLog.log("initializer","found tine.properties in java.ext.dirs directory",0,null,1);
            found = true;
          }
        }
        if (!found)
        {
          if (!(new File(prpsFileName).exists()))
          { // simple check on ext dirs directory didn't find anything
            prpsFileName = System.getProperty("java.home")+File.separator+"tine.properties";
          }
          else
          {
            MsgLog.log("initializer","found tine.properties in java.home directory",0,null,1);
            found = true;
          }
        }
        tineProperties.load(new FileInputStream(prpsFileName));
      }
      catch (IOException e)
      {
        MsgLog.log("initializer","tine.properties file not found",0,null,1);
        MsgLog.log("initializer","use local environment to find repositories",0,null,1);
      }
      addrFileLocation = getTineHome()+File.separator+"fecaddr.csv";
      eqpFileLocation = getTineHome()+File.separator+"eqpdbase.csv";
      cshostsFileLocation = getTineHome()+File.separator+"cshosts.csv";
      fecidFileLocation = getFecHome()+File.separator+"fecid.csv";
      exportsFileLocation = getFecHome()+File.separator+"exports.csv";
      usersFileLocation = getFecHome()+File.separator+"users.csv";
      aliasFileLocation = getFecHome()+File.separator+"alias.csv";
      netsFileLocation = getFecHome()+File.separator+"ipnets.csv";
      alarmwFileLocation = getFecHome()+File.separator+"almwatch.csv";
      historyFileLocation = getFecHome()+File.separator+"history.csv";
      logFileLocation = getLogHome()+File.separator+"fec.log";
      myipFileLocation = getFecHome()+File.separator+"myaddr.csv";
      int bs = 0;
      try {bs = Integer.parseInt(System.getProperty("srv.RECV_BUFFER_SIZE", "0"));}
      catch (Exception ignore) {};
      if (bs > 0x2000) srvRcvBufferSize = bs;
      try {bs = Integer.parseInt(System.getProperty("cln.RECV_BUFFER_SIZE", "0"));}
      catch (Exception ignore) {};
      if (bs > 0x2000) clnRcvBufferSize = bs;
      try {bs = Integer.parseInt(System.getProperty("srv.TIME_TO_LIVE", "0"));}
      catch (Exception ignore) {};
      if (bs > 1) sckTimeToLive = bs;
      try {bs = Integer.parseInt(System.getProperty("srv.PACKET_MTU", "0"));}
      catch (Exception ignore) {};
      try {bs = Integer.parseInt(System.getProperty("srv.SEND_BUFFER_SIZE", "0"));}
      catch (Exception ignore) {};
      if (bs > 0x1000) srvSndBufferSize = bs;
      try {bs = Integer.parseInt(System.getProperty("cln.SEND_BUFFER_SIZE", "0"));}
      catch (Exception ignore) {};
      if (bs > 0x1000) clnSndBufferSize = bs;
      if (bs >= 512 && bs <= 64000) srvPacketMtu = bs;
      // give this a try ....
      Map<Thread, StackTraceElement[]> a = Thread.getAllStackTraces();
      for (Thread t : a.keySet())
      { // if no one changed the main thread name this will work ...
        if ("main".equals(t.getName()))
        {
          StackTraceElement[] stack = t.getStackTrace();
          if (stack != null && stack.length > 0)
          {
            StackTraceElement main = stack[stack.length - 1];
            srvStartup = main.getClassName();
          }
          break;
        }
      }
      File f1 = new File (".");
      try
      {
        srvCwd = f1.getCanonicalPath();
      }
      catch (IOException e)
      {
        MsgLog.log("DefaultTInitializer.initialize", "cannot get working directory: "+e.getMessage(),TErrorList.io_error,e,0);
      }
      try
      {
        String pnam = ManagementFactory.getRuntimeMXBean().getName();
        pid = Integer.parseInt(pnam.substring(0, pnam.indexOf('@')));
      }
      catch (Exception e)
      {
        MsgLog.log("TInitializer","cannot get pid!",TErrorList.code_failure,e,0);
      }
      hasInitialzed = true;
    }
    class IpNameHndlr implements csvHandler
    {
      String[] ip = null;
      public IpNameHndlr(String[] ip)
      {
        this.ip = ip;
      }
      public int process(String strValue,int index)
      {
        if (strValue == null || strValue.length() == 0) return 0;
        if (ip != null) ip[0] = strValue;
        return 0;
      }
    }
    private String myip = null;
    public String getMyIpAddr()
    {
      if (myip != null) return myip;
      // try file
      csvColumn[] ipCols = new csvColumn[1];
      String[] ipa = new String[1];
      ipCols[0] = new csvColumn("ADDRESS","",new IpNameHndlr(ipa));
      csv myipFile = new csv(getCfgResource(myipFileLocation));
      int rc = myipFile.readFile(ipCols);
      myipFile.close();
      if (rc == 0 && ipa[0] != null)
      { // file found !
        TFecLog.log("fix local ip address to "+ipa[0]+" from file");
        MsgLog.log("TInitializer","fix local ip address to "+ipa[0]+" from file",0,null,1);
        return myip = ipa[0];     
      }
      String ip = System.getProperty("fec.address");;
      if (ip == null) ip=System.getenv("FEC_ADDRESS");
      if (ip != null)
      { // env variable set !
        TFecLog.log("fix local ip address to "+ip+" from environment");
        MsgLog.log("TInitializer","fix local ip address to "+ip+" from environment",0,null,1);
        return myip = ip;
      }
      // try the local host
      // this is normally what happens (but try the others first)
      ip = "0.0.0.0";
      try
      {
        ip = InetAddress.getLocalHost().getHostAddress();
        MsgLog.log("TInitializer","fix local ip address from local host address",0,null,1);
        TFecLog.log("fix local ip address to "+ip+" from local host");
      }
      catch (UnknownHostException e)
      {
        MsgLog.log("TInitializer","cannot get local host!",TErrorList.host_not_resolved,e,0);       
      }
      return myip = ip;
    }
    public String getSystemStartup()
    {
      return srvStartup;
    }
    public String getSystemCwd()
    {
      return srvCwd;
    }
    public int getPid()
    {
      return pid;
    }
    public String getVersion()
    {
      return new String("" + srvMajor + "." + srvMinor + "." + srvRevision);
    }
    public int getMajorVersion()
    {
      return srvMajor;
    }
    public int getMinorVersion()
    {
      return srvMinor;
    }
    public int getRevision()
    {
      return srvRevision;
    }
    public int getRevisionId()
    {
      return srvMinor * 256 + srvRevision;
    }
    public int getBuildId()
    {
      return buildId;
    }
    public String getOs()
    {
      return srvOs;
    }
    public synchronized String getTineHome()
    {
      if (tineHome == null)
      {
        String home = System.getProperty("tine.home");
        if (home != null)
          MsgLog.log("initializer","tine home set from JVM argument",0,null,1);
        else
        {
          home = tineProperties.getProperty("tine.home");
          if (home != null)
            MsgLog.log("initializer","tine home set from tine properties",0,null,1);
          else
          {
            MsgLog.log("initializer","trying to determine tine home from local environment",0,null,1);
            home = System.getenv("TINE_HOME");
            if (home != null)
              MsgLog.log("initializer", "tine home set from TINE_HOME environment",0,null,1);
            else
            {
              home = System.getenv("CONTROLDB");
              if (home != null)
                MsgLog.log("initializer","tine home set from legacy environment",0,null,0);
              else
                MsgLog.log("initializer","unable to determine tine home from local environment",0,null,1);
            }
          }
        }
        if (home != null)
        {
          if (home.endsWith("/") || home.endsWith("\\")) home = home.substring(0, home.length() - 1);                              // ...
        }
        if (home == null)
        {
          home = ".";
          File f = new File(home);
          MsgLog.log("initializer", "using working directory : " + f.getAbsolutePath() + " as tine home",0,null,1);
        }
        // home = "."; // test: force an unresolved ens
        tineHome = new String(home);
      }
      return tineHome;
    }
    public synchronized String getFecHome()
    {
      if (fecHome == null)
      {
        String home = System.getProperty("fec.home");
        if (home == null) home = tineProperties.getProperty("fec.home");
        if (home == null) home = System.getenv("FEC_HOME");
        if (home == null) home = System.getenv("FECDB");
        if (home != null)
        {
          if (home.endsWith("/") || home.endsWith("\\")) home = home.substring(0, home.length() - 1);
        }
        fecHome = home != null ? new String(home) : getTineHome();
      }
      return fecHome;
    }
    public synchronized String getHistoryHome()
    {
      if (historyHome == null)
      {
        String home = System.getProperty("history.home");
        if (home == null) home = tineProperties.getProperty("history.home");
        if (home == null) home = System.getenv("TINE_HISTORY_HOME");
        if (home == null) home = System.getenv("HISTORY_HOME");
        if (home == null) home = System.getenv("HISTORYDB");
        if (home != null)
        {
          if (home.endsWith("/") || home.endsWith("\\")) home = home.substring(0, home.length() - 1);
        }
        else
        {
          home = getFecHome() + File.separator+".."+File.separator+"HISTORY";
        }
        historyHome = home;
      }
      return historyHome;
    }
    public synchronized String getTineCache()
    {
      if (tineCache == null)
      {
        String cache = System.getProperty("tine.cache");
        if (cache == null) cache = tineProperties.getProperty("tine.cache");
        if (cache == null) cache = System.getenv("TINE_CACHE");
        if (cache == null)
        {
          if (File.separatorChar == '/')
          { // unix or mac
            cache = "/var/lib";
            boolean useTmp = false;
            try
            {
              if (!new File("/var/lib/tine").exists()) useTmp = true;
            }
            catch (Exception any)
            {
              useTmp = true;
            }
            if (useTmp) cache = "/var/tmp";
          }
          else if (File.separatorChar == '\\')
          { // windows
            cache = System.getenv("SystemDrive");
            if (cache == null) cache = "C:";
          }
          else
          {
            cache = ".";
          }   
        }
        tineCache = cache;
      }
      return tineCache;
    }
    public synchronized String getLogHome()
    {
      if (logHome == null)
      {
        String home = System.getProperty("log.home");
        if (home == null) home = tineProperties.getProperty("log.home");
        if (home == null) home = System.getenv("FEC_LOG");
        if (home == null) home = System.getenv("FECLOG");
        if (home == null) home = System.getenv("LOG_HOME");
        if (home != null)
        {
          if (home.endsWith("/") || home.endsWith("\\")) home = home.substring(0, home.length() - 1);
        }
        logHome = home != null ? new String(home) : getFecHome();
      }
      return logHome;
    }
    private synchronized BufferedReader getCfgResource(String fileLocation)
    {
      if (fileLocation == null) return null;
      try
      {
        return new BufferedReader(new InputStreamReader(new FileInputStream(fileLocation)));
      }
      catch (Exception e)
      {
        if (fileLocation == cshostsFileLocation)
          MsgLog.log("initializer", "Could not open configuration file : " + e,0,null,0);
        return null;
      }
    }
    public synchronized BufferedWriter getFecLogWriter()
    {
      try
      {
        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFileLocation, true)));
      }
      catch (Exception e)
      {
        MsgLog.log("initializer", "Could not open fec log file " + logFileLocation + " for writing : " + e,0,null,0);
        return null;
      }
    }
    public synchronized FileHandler getFecLogResource()
    {
      try
      {
        return new FileHandler(logFileLocation, 50000, 3, true);
      }
      catch (Exception e)
      {
        MsgLog.log("initializer", "Could not open fec log file " + logFileLocation + " for reading : " + e,0,null,0);
        return null;
      }
    }
    public BufferedReader getFecIdResource()
    {
      return getCfgResource(fecidFileLocation);
    }
    public BufferedReader getExportsResource(String eqmName)
    {
      BufferedReader br;
      if (eqmName != null) exportsFileLocation = getFecHome()+File.separator+eqmName+File.separator+"exports.csv";
      if ((br = getCfgResource(exportsFileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        exportsFileLocation = getFecHome()+File.separator+"exports.csv";
        br = getCfgResource(exportsFileLocation);
      }
      return br;
    }
    public BufferedReader getUsersResource(String eqmName,String tag)
    {
      BufferedReader br;
      String fn = File.separator;
      if (tag != null && tag.length() > 0) fn += tag + "-";
      fn += "users.csv";
      if (eqmName != null) usersFileLocation = getFecHome()+File.separator+eqmName+fn;
      if ((br = getCfgResource(usersFileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        usersFileLocation = getFecHome() + fn;
        br = getCfgResource(usersFileLocation);
      }
      return br;
    }
    public BufferedReader getGroupsResource(String eqmName,String grpName)
    {
      if (grpName == null || grpName.length() == 0) return null;
      BufferedReader br;
      String fn = File.separator + grpName + "-members.csv";
      if (eqmName != null) grpsFileLocation = getFecHome()+File.separator+eqmName+fn;
      if ((br = getCfgResource(grpsFileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        grpsFileLocation = getFecHome()+fn;
        br = getCfgResource(grpsFileLocation+fn);
      }
      return br;
    }
    public BufferedReader getNetsResource(String eqmName,String tag)
    {
      BufferedReader br;
      String fn = File.separator;
      if (tag != null && tag.length() > 0) fn += tag + "-";
      fn += "ipnets.csv";
      if (eqmName != null) netsFileLocation = getFecHome() + File.separator + eqmName + fn;
      if ((br = getCfgResource(netsFileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        netsFileLocation = getFecHome() + fn;
        br = getCfgResource(netsFileLocation);
      }
      return br;
    }
    public BufferedReader getAliasResource(String eqmName)
    {
      BufferedReader br;
      if (eqmName != null) aliasFileLocation = getFecHome()+File.separator+eqmName+File.separator+"alias.csv";
      if ((br = getCfgResource(aliasFileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        aliasFileLocation = getFecHome()+File.separator+"alias.csv";
        br = getCfgResource(aliasFileLocation);
      }
      return br;
    }
    public BufferedReader getHistoryResource(String eqmName,String fileName)
    {
      BufferedReader br;
      String hstfn = historyFileLocation;
      boolean resetFileLocation = false;
      if (fileName == null)
      {
        fileName = "history.csv";
        resetFileLocation = true;
      }
      if (eqmName != null)
      {
        hstfn = getFecHome()+File.separator+eqmName+File.separator+fileName;
      }
      if ((br = getCfgResource(hstfn)) == null)
      { // first try local name subdirectory then try the standard home
        hstfn = getFecHome()+File.separator+fileName;
        br = getCfgResource(hstfn);
      }
      if (resetFileLocation) historyFileLocation = hstfn;
      return br;
    }
    public BufferedReader getAlmWatchResource(String eqmName)
    {
      BufferedReader br;
      if (eqmName != null) alarmwFileLocation = getFecHome()+File.separator+eqmName+File.separator+"almwatch.csv";
      if ((br = getCfgResource(alarmwFileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        alarmwFileLocation = getFecHome()+File.separator+"almwatch.csv";
        br = getCfgResource(alarmwFileLocation);
      }
      return br;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getAddressResource()
     */
    public BufferedReader getAddressResource()
    {
      return getCfgResource(addrFileLocation);
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getENSAddress()
     */
    public String getENSAddress()
    {
      return ENS;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getEquipmentResource()
     */
    public BufferedReader getEquipmentResource()
    {
      return getCfgResource(eqpFileLocation);
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getHostsResource()
     */
    public BufferedReader getHostsResource()
    {
      return getCfgResource(cshostsFileLocation);
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getGCastAddress()
     */
    private boolean gcastaddrdone = false;
    public String getGCastAddress()
    {
      if (!gcastaddrdone)
      {
        gcastaddrdone = true;
        // first try csv
        csvColumn[] addrCols = new csvColumn[1];
        addrHndlr hdlr = new addrHndlr();
        addrCols[0] = new csvColumn("ADDRESS", "", hdlr);
        int rc;
        csv mcastMaskFile = new csv(getCfgResource(getFecHome() +File.separator+ "gcastmask.csv"));
        rc = mcastMaskFile.readFile(addrCols);
        mcastMaskFile.close();
        if (rc != 0)
        {
          mcastMaskFile = new csv(getCfgResource(getTineHome()+File.separator+"gcastmask.csv"));
          rc = mcastMaskFile.readFile(addrCols);
          mcastMaskFile.close();
        }
        if (rc == 0)
        {
          GCAST = hdlr.getStrValue();
          TFecLog.log("set globals multicast address from config file to " + MCAST);
        }
        String addr = System.getProperty("tine.gcast.addr");
        if (addr == null) addr = System.getenv("TINE_GCAST_ADDR");
        if (addr != null)
        {
          TFecLog.log("set globals multicast address from environment to " + addr);
          String[] parts = addr.split("\\.");
          if (parts != null && parts.length == 4) GCAST = addr;
        }
        addr = System.getProperty("tine.gcast.mask");
        if (addr == null) addr = System.getenv("TINE_GCAST_MASK");
        if (addr != null)
        { // no difference at the moment ...
          TFecLog.log("set globals multicast address from environment to " + addr);
          String[] parts = addr.split("\\.");
          if (parts != null && parts.length == 4) GCAST = addr;
        }
      }
      return GCAST;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getGCastPort()
     */
    public int getGCastPort()
    {
      return GCAST_PORT;
    }
    public String getNetCastAddress()
    {
      return NETCAST;
    }
    public int getNetCastPort()
    {
      return NETCAST_PORT;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getMCastAddress()
     */
    class addrHndlr implements csvHandler
    {
      private String strValue;
      public int process(String strValue, int index)
      {
        if (strValue == null || strValue.length() == 0) return 0;
        String[] parts = strValue.split("\\.");
        if (parts != null && parts.length == 4) this.strValue = new String(strValue);
        return 0;
      }
      public String getStrValue()
      {
        return strValue;
      }
    }
    private boolean mcastaddrdone = false;
    public String getMCastAddress()
    {
      if (!mcastaddrdone)
      {
        mcastaddrdone = true;
        // first try csv file
        csvColumn[] addrCols = new csvColumn[1];
        addrHndlr hdlr = new addrHndlr();
        addrCols[0] = new csvColumn("ADDRESS", "", hdlr);
        int rc;
        csv mcastMaskFile = new csv(getCfgResource(getFecHome()+File.separator+"mcastmask.csv"));
        rc = mcastMaskFile.readFile(addrCols);
        mcastMaskFile.close();
        if (rc != 0)
        {
          mcastMaskFile = new csv(getCfgResource(getTineHome()+File.separator+"mcastmask.csv"));
          rc = mcastMaskFile.readFile(addrCols);
          mcastMaskFile.close();
        }
        if (rc == 0)
        {
          MCAST = hdlr.getStrValue();
          TFecLog.log("set server multicast address from config file to " + MCAST);
        }
        String addr = System.getProperty("tine.mcast.addr");
        if (addr == null) addr = System.getenv("TINE_MCAST_ADDR");
        if (addr != null)
        {
          TFecLog.log("set server multicast address from environment to " + addr);
          String[] parts = addr.split("\\.");
          if (parts != null && parts.length == 4) MCAST = addr;
        }
        addr = System.getProperty("tine.mcast.mask");
        if (addr == null) addr = System.getenv("TINE_MCAST_MASK");
        if (addr != null)
        { // no difference at the moment ...
          TFecLog.log("set server multicast address from environment to " + addr);
          String[] parts = addr.split("\\.");
          if (parts != null && parts.length == 4) MCAST = addr;
        }
      }
      return MCAST;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getMCastPort()
     */
    public int getMCastPort()
    {
      return MCAST_PORT;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getSrvPort()
     */
    public int getSrvPort()
    {
      return SRV_PORT;
    }
    /**
     * @see de.desy.tine.startup.TInitializer#getTCPPort()
     */
    public int getTCPPort()
    {
      return TCP_PORT;
    }
    public int getClnPort()
    {
      return UDP_CLN_PORT;
    }
    public BufferedReader getAlmDefinitionResource(String eqmName)
    {
      BufferedReader br;
      if (eqmName == null) return null;
      String fileLocation = getFecHome() + File.separator + eqmName + File.separator + "alarms.csv";
      if ((br = getCfgResource(fileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        fileLocation = getFecHome() + File.separator + eqmName + "-alarms.csv";
        br = getCfgResource(fileLocation);
        if ((br = getCfgResource(fileLocation)) == null)
        { // last chance
          fileLocation = getFecHome() + File.separator + "alarms.csv";
          br = getCfgResource(fileLocation);
        }
      }
      return br;
    }
    public BufferedReader getDevicesResource(String eqmName)
    {
      BufferedReader br;
      if (eqmName == null) return null;
      String fileLocation = getFecHome() + File.separator + eqmName + File.separator + "devices.csv";
      if ((br = getCfgResource(fileLocation)) == null)
      { // first try local name subdirectory then try the standard home
        fileLocation = getFecHome() + File.separator + eqmName + "-devices.csv";
        br = getCfgResource(fileLocation);
        if ((br = getCfgResource(fileLocation)) == null)
        { // last chance
          fileLocation = getFecHome() + File.separator + "devices.csv";
          br = getCfgResource(fileLocation);
        }
      }
      return br;
    }
    public int getClnRcvBufferSize()
    {
      return clnRcvBufferSize;
    }
    public int getClnSndBufferSize()
    {
      return clnRcvBufferSize;
    }
    public void setClnRcvBufferSize(int bufferSize)
    {
      if (bufferSize < 0x4000) bufferSize = 0x4000;
      DefaultTInitializerFactory.clnRcvBufferSize = bufferSize;
    }
    public void setClnSndBufferSize(int bufferSize)
    {
      if (bufferSize < 0x1000) bufferSize = 0x1000;
      DefaultTInitializerFactory.clnSndBufferSize = bufferSize;
    }
    public int getSckTimeToLive()
    {
      return sckTimeToLive;
    }
    public void setSckTimeToLive(int ttl)
    {
      if (ttl < 1) ttl = 1;
      DefaultTInitializerFactory.sckTimeToLive = ttl;
    }
    public int getSrvPacketMtu()
    {
      return srvPacketMtu;
    }
    public void setSrvPacketMtu(int mtu)
    {
      if (mtu < 512) mtu = 512;
      if (mtu > 64000) mtu = 64000;
      DefaultTInitializerFactory.srvPacketMtu = mtu;
    }
    public int getSrvRcvBufferSize()
    {
      return srvRcvBufferSize;
    }
    public int getSrvSndBufferSize()
    {
      return srvSndBufferSize;
    }
    public void setSrvRcvBufferSize(int bufferSize)
    {
      if (bufferSize < 0x4000) bufferSize = 0x4000;
      DefaultTInitializerFactory.srvRcvBufferSize = bufferSize;
    }
    public void setSrvSndBufferSize(int bufferSize)
    {
      if (bufferSize < 0x1000) bufferSize = 0x1000;
      DefaultTInitializerFactory.srvSndBufferSize = bufferSize;
    }
    public void setENSAddress(String ip)
    {
      ENS = ip;
    }
    public int getStreamPort()
    {
      return STREAM_PORT;
    }
    public int getPipePort()
    {
      return PIPE_PORT;
    }
    public boolean isRichClient() { return isRichClient; }
    public void setRichClient(boolean value) { isRichClient = value; }
  }
  /**
   * @see de.desy.tine.startup.TInitializerFactory#getInitializer()
   */
  public synchronized TInitializer getInitializer()
  {
    if (instance == null) instance = new DefaultTInitializer();
    return instance; // new DefaultTInitializer();
  }
}
TOP

Related Classes of de.desy.tine.startup.DefaultTInitializerFactory$DefaultTInitializer$IpNameHndlr

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.