Example usage for java.net UnknownHostException printStackTrace

List of usage examples for java.net UnknownHostException printStackTrace

Introduction

In this page you can find the example usage for java.net UnknownHostException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:ComputeNode.java

@Override
public Boolean taskTransferRequest(Task task) throws RemoteException {

    Double load = getCurrentLoad();
    myNodeStats.getNoOfTransferRequests().incrementAndGet();

    lg.log(Level.FINER, "currLoad :" + load + " expectedLoad: " + task.getExpectedLoad()
            + " overLoadThreshold :" + overLoadThreshold);

    if (load + task.getExpectedLoad() > overLoadThreshold) {
        return false;
    }//from   w ww .  j a va2 s.c  o m

    try {
        InetAddress ownIP = InetAddress.getLocalHost();
        String localIP = ownIP.getHostAddress();
        task.setNode(new Pair(id, localIP));

    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    server.updateTaskTransfer(task);
    Thread t = new TaskExecutor(task);
    t.start();

    // spawn task request...
    return true;
}

From source file:com.vmware.vchs.publicapi.samples.GatewayRuleSample.java

/**
 * This method is to get Href for network on which the Nat rules need to be Applied.
 * // w w w  . j a  v a 2s  . c  om
 * @param gatewayHref
 *            the href to the gateway to be used
 * @return href the interface on which the rules need to be applied
 */
private String getNetworkHref(String gatewayHref) {
    // Represents the Gateway
    HttpResponse response = HttpUtils.httpInvoke(vcd.get(gatewayHref, options));
    GatewayType gateway = HttpUtils.unmarshal(response.getEntity(), GatewayType.class);

    // Retrieving the configuration for the Gateway
    GatewayConfigurationType gatewayConfig = gateway.getConfiguration();

    // Retrieving the Gateway Interfaces
    GatewayInterfacesType gatewayInterfaces = gatewayConfig.getGatewayInterfaces();
    List<GatewayInterfaceType> gatewayInterfaceList = gatewayInterfaces.getGatewayInterface();
    String networkHref = null;

    // Iterating through Gateway Interface list to select a Gateway Interface to which the
    // externalIp provided belongs
    for (GatewayInterfaceType gatewayInterface : gatewayInterfaceList) {
        if (gatewayInterface.getInterfaceType().equals("uplink")) {
            for (int i = 0; i < gatewayInterface.getSubnetParticipation().size(); i++) {
                IpRangesType ipRanges = gatewayInterface.getSubnetParticipation().get(i).getIpRanges();
                List<IpRangeType> ipRange = ipRanges.getIpRange();

                for (IpRangeType ipR : ipRange) {
                    long startAddress = 0l;
                    long endAddresss = 0l;
                    long ipToTest = 0l;

                    try {
                        startAddress = ipToLong(InetAddress.getByName(ipR.getStartAddress()));
                        endAddresss = ipToLong(InetAddress.getByName(ipR.getEndAddress()));
                        ipToTest = ipToLong(InetAddress.getByName(options.externalIp));
                    } catch (UnknownHostException e) {
                        e.printStackTrace();
                    }

                    if (ipToTest >= startAddress && ipToTest <= endAddresss) {
                        // The Network that is to be used to apply NAT Rules
                        networkHref = gatewayInterface.getNetwork().getHref();
                        break;
                    }
                }
            }
        }
    }

    if (null == networkHref) {
        throw new RuntimeException("Could not find network for gateway Href: " + gatewayHref);
    }

    return networkHref;
}

From source file:org.mandar.analysis.recsys2014.recsysMain.java

public void run() {
    // We first need to configure the data access.
    LenskitConfiguration dataConfig = this.configureDAO(DBSettings.TRAINING_COLLECTION);
    // Now we create the LensKit configuration...
    LenskitConfiguration config = new LenskitConfiguration();
    if (algo.equals("svd")) {
        config = this.configureSVDRecommender(numFeatures, numIterations, regularizationParam,
                stoppingCondition, threshold);
    } else if (algo.equals("ii")) {
        config = this.configureIIRecommender(numNeighbours, similarityModel);
    } else if (algo.equals("uu")) {
        config = this.configureUURecommender(numNeighbours);
    } else if (algo.equals("so")) {
        config = this.configureSORecommender(damping);
    } else if (algo.equals("tfidf")) {
        config = this.configureTFIDFRecommender();
    }/*from w  ww . j  a  va2  s . c  o m*/

    // There are more parameters, roles, and components that can be set. See the
    // JavaDoc for each recommender algorithm for more information.
    // Now that we have a factory, build a recommender from the configuration
    // and data source. This will compute the similarity matrix and return a recommender
    // that uses it.
    LenskitRecommender rec = null;
    try {
        LenskitRecommenderEngine engine = LenskitRecommenderEngine.newBuilder().addConfiguration(config)
                .addConfiguration(dataConfig).build();
        rec = engine.createRecommender(dataConfig);

    } catch (RecommenderBuildException e) {
        e.printStackTrace();
        System.exit(1);
    }
    // we want to recommend items
    if ("training".equals(this.goal)) {
        ItemRecommender irec = rec.getItemRecommender();
        assert irec != null; // not null because we configured one
        // for users
        try {
            MongoClient mongoClient = new MongoClient(DBSettings.DBHOST);
            DB db = mongoClient.getDB(DBSettings.DATABASE);
            DBCollection collection = db.getCollection(DBSettings.MOVIES_COLLECTION);
            for (long user : users) {
                // get 10 recommendation for the user
                List<ScoredId> recs = irec.recommend(user, 10);
                System.out.format("Recommendations for %d:\n", user);
                for (ScoredId item : recs) {
                    DBObject obj = collection.findOne(new BasicDBObject(DBSettings.FIELDS.movie, item.getId()));
                    String recTitle = obj.get("title").toString();
                    String recDirector = obj.get("director").toString();
                    String recRel = obj.get("release_date").toString();
                    String recStars = obj.get("stars").toString();

                    System.out.format("\tID:%d, %s, %s Directed By: %s Starring: %s\n", item.getId(), recTitle,
                            recRel, recDirector, recStars);
                }
            }
            mongoClient.close();
        } catch (UnknownHostException u) {
            u.printStackTrace();
        }
    } else if ("eval".equals(this.goal)) {
        //ItemScorer iscorer = rec.getItemScorer();
        RatingPredictor rat = rec.getRatingPredictor();
        File outFile = new File("data/participant_solution_" + algo + ".dat");
        String line = "";
        //String cvsSplitBy = ",";
        long eng = 0;
        int count = 0;
        try {
            long lines = Utils.countLines("data/test_solution.dat");
            //outFile.delete();
            BufferedWriter brout = new BufferedWriter((new FileWriter(outFile, false)));
            //BufferedReader br = new BufferedReader(new FileReader(csvData));
            long progress = 0;
            //br.readLine();
            System.out.println(
                    "Reading from Test Set and writing result " + "data/participant_solution_" + algo + ".dat");

            MongoClient mongoClient = new MongoClient(DBSettings.DBHOST);
            DB db = mongoClient.getDB(DBSettings.DATABASE);
            DBCollection collection = db.getCollection(DBSettings.TEST_COLLECTION_EMPTY);
            DBCursor cur = collection.find();

            ArrayList<DBObject> arr = new ArrayList<DBObject>(cur.size());

            System.out.println("Making ObjectArrayList out of test collection result");
            while (cur.hasNext()) {
                DBObject buff = cur.next();
                eng = (long) Math.abs(rat.predict(Long.parseLong(buff.get("uID").toString()),
                        Long.parseLong(buff.get("movieID").toString())));
                buff.put("engagement", eng);
                arr.add(buff);
                count++;
            }

            cur.close();
            //Now sort this by uID (desc), engagement (desc) and tweetID (desc)
            System.out.println("Sorting ObjectArrayList");
            Collections.sort(arr, new MongoComparator());
            for (int i = 0; i < arr.size(); i++) {
                brout.write(arr.get(i).get("uID") + "," + arr.get(i).get("tweetID") + ","
                        + arr.get(i).get("engagement"));
                brout.newLine();
                progress++;
                if ((progress * 100 / lines) % 10 >= 0 && (progress * 100 / lines) % 10 <= 1) {
                    System.out.println("File write Progress: " + (progress * 100 / lines) + " %");
                }
            }
            brout.close();

            ProcessBuilder pbr = new ProcessBuilder("java", "-jar",
                    "rscevaluator-0.1-jar-with-dependencies.jar", "data/test_solution.dat",
                    "data/participant_solution_" + algo + ".dat");
            Process p = pbr.start();

            BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
            double resultbuff = 0.0d;
            while ((line = is.readLine()) != null) {
                if (line.contains("nDCG@10:")) {
                    resultbuff = Double.parseDouble(line.substring(9));
                }
                System.out.println(line);
            }
            System.out.println("Writing evaluation results to MongoDB");
            this.writeAlgoTestResults(resultbuff, db);
            mongoClient.close();
            p.waitFor();

        } catch (FileNotFoundException f) {
            f.printStackTrace();
        } catch (IOException f) {
            f.printStackTrace();
        } catch (InterruptedException i) {
            i.printStackTrace();
        } catch (NullPointerException n) {
            n.printStackTrace();
        }
    }
}

From source file:org.rifidi.emulator.reader.llrp.module.LLRPReaderModule.java

public LLRPReaderModule(ControlSignal<Boolean> powerControlSignal, GeneralReaderPropertyHolder properties) {

    super(LLRPReaderModuleOffPowerState.getInstance(), powerControlSignal);

    consoleLogger = LogFactory.getLog("console." + properties.getReaderName());

    consoleLogger.info(/*from w  ww  .jav  a  2  s  . c o m*/
            LLRPReaderModule.startupText + "Instantiated LLRPReader with name: " + properties.getReaderName());

    consoleLogger.info(LLRPReaderModule.startupText + properties.getReaderName() + " has "
            + properties.getNumAntennas() + " antennas");
    this.name = properties.getReaderName();

    consoleLogger.info(LLRPReaderModule.startupText + properties.getReaderName() + " has "
            + properties.getNumGPIs() + " GPI Ports" + " and " + properties.getNumGPOs() + " GPO Ports");

    digester = new CommandXMLDigester();
    digester.parseToCommand(this.getClass().getClassLoader().getResourceAsStream(XMLLOCATION + "reader.xml"));

    HashMap<Integer, Antenna> antennaList = new HashMap<Integer, Antenna>();
    for (int i = 0; i < properties.getNumAntennas(); i++) {
        antennaList.put(i, new Antenna(i, name));
    }

    LLRPTagMemory tagMem = new LLRPTagMemory();

    /* Make a Radio for the reader */
    GenericRadio genericRadio = new GenericRadio(antennaList, 25, name);

    this.llrpSR = new LLRPReaderSharedResources(genericRadio, tagMem, powerControlSignal,
            properties.getReaderName(), new LLRPExceptionHandler(), this.digester,
            new ControlSignal<Boolean>(false), new ControlSignal<Boolean>(false), antennaList.size());

    int numGPOs = properties.getNumGPOs();
    int numGPIs = properties.getNumGPIs();

    for (int i = 0; i < numGPIs; i++) {
        llrpSR.getGpioController().addGPIPort(i);
    }
    for (int i = 0; i < numGPOs; i++) {
        llrpSR.getGpioController().addGPOPort(i);
    }

    setDefaultProperties(llrpSR);

    String inet = ((String) properties.getProperty("inet_address")).split(":")[0];
    int port = Integer.parseInt(((String) properties.getProperty("inet_address")).split(":")[1]);

    adminInterface = new LLRPReaderModuleAdministration(this, inet, port);

    // Observer for Connection
    connectionEventObserver = new ConnectionEventObserver(llrpSR.getInteractiveConnectionSignal(), name);

    // Create a ReportController for sending Reports
    LLRPReportControllerFactory.getInstance().createController(name);

    ROSpecControllerFactory.getInstance().createController(name);

    this.interactiveCommandAdapter = new ReflectiveCommandAdapter("Interactive", new LLRPCommandFormatter(),
            llrpSR.getExceptionHandler(), this.llrpSR, new RawCommandSearcher());

    this.interactiveCommandController = new InteractiveCommandController(
            new LoginAuthenticatedCommandControllerOperatingState(this.interactiveCommandAdapter),
            llrpSR.getInteractivePowerSignal(), llrpSR.getInteractiveConnectionSignal(), null);
    // Remember to set the Communication at the moment it's
    // available [null = this.interactiveCommunication]

    boolean enableServerMode = new Boolean((String) properties.getProperty("servermode"));
    if (enableServerMode) {
        logger.debug("ServerMode enabled by wizard. " + "=> Startup in ServerMode");
        String llrpInet = ((String) properties.getProperty("inet_address")).split(":")[0];
        int llrpPort = Integer.parseInt(((String) properties.getProperty("llrp_inet_address")).split(":")[1]);
        InetAddress inetAddr = null;
        try {
            inetAddr = Inet4Address.getByName(llrpInet);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        LLRPReaderModuleConnectionType connectionType = new LLRPReaderModuleConnectionType(true, inetAddr,
                llrpPort);
        adminInterface.preEnabledServerMode(connectionType);
    }
}

From source file:org.openhab.binding.irtrans.internal.IRtransGenericBindingProvider.java

/**
 * {@inheritDoc}// w w  w.  j  a va 2 s .  co m
 */
public InetSocketAddress getInetSocketAddress(String itemName, Command command) {
    InetSocketAddress socketAddress = null;
    try {
        socketAddress = new InetSocketAddress(InetAddress.getByName(getHost(itemName, command)),
                getPort(itemName, command));
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return socketAddress;
}

From source file:org.openhab.binding.irtrans.internal.IRtransGenericBindingProvider.java

/**
 * {@inheritDoc}/*  ww  w .j av a 2 s  .co m*/
 */
public List<InetSocketAddress> getInetSocketAddresses(String itemName) {
    List<InetSocketAddress> theList = new ArrayList<InetSocketAddress>();
    for (Command command : getAllCommands(itemName)) {
        InetSocketAddress anAddress = null;
        try {
            anAddress = new InetSocketAddress(InetAddress.getByName(getHost(itemName, command)),
                    getPort(itemName, command));
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        theList.add(anAddress);
    }
    return theList;
}

From source file:org.act.index.server.MetaService.java

public int init() {
    // get manager ip list and port from CONF FILE
    String iplist = PublicParam.CONFIG.getStringValue(Configure.CONFIG_MANAGER, Configure.CONF_IP_ADDR_LIST,
            null);/*from  ww w.ja v  a  2  s  .co  m*/
    int managerPort = PublicParam.CONFIG.getIntValue(Configure.CONFIG_MANAGER, Configure.CONF_PORT, 0);
    int serverPort = PublicParam.CONFIG.getIntValue(Configure.CONFIG_SERVER, Configure.CONF_PORT, 0);
    if (iplist == null || managerPort <= 0) {
        LOG.error("init manager ip is null or manager port <= 0, must be exit.");
        return ErrorMessage.EXIT_GENERAL_ERROR;
    }
    LOG.debug("manager list(" + iplist + ", manager port(" + managerPort + ").");
    List<Address> addrs = new ArrayList<Address>();

    String[] ips = iplist.split("\\|");
    for (String string : ips) {
        addrs.add(new Address(string, managerPort));
    }
    if (addrs.size() != 2) {
        LOG.debug("must have to manager, check you manager list");
        return ErrorMessage.EXIT_GENERAL_ERROR;
    }
    String ipAddr = PublicParam.CONFIG.getStringValue(Configure.CONFIG_MANAGER, Configure.CONF_IP_ADDR, null);
    // managerAddr = new Address(ipAddr, port);
    managerAddr = new Address(ipAddr, managerPort);

    String localIP = "";
    try {
        localIP = Inet4Address.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Address localAddr = new Address(localIP, serverPort);
    int i;
    for (i = 0; i < ips.length && localIP.compareTo(ips[i]) != 0; i++) {
        ;
    }
    if (i == ips.length) {
        LOG.error("local ip(" + localIP + ") not in ip list, must be exit.");
        return ErrorMessage.EXIT_GENERAL_ERROR;
    }
    return GlobalMessage.ISS_SUCCESS;
}

From source file:com.cnm.cnmrc.fragment.vodtvch.VodDetail.java

@Override
public void onClick(View v) {
    // sidebar  return.
    // 2013-12-06 comment? ? ?.
    // /*w  ww  . j a v a  2s.co  m*/
    //      if (UiUtil.isSlidingMenuOpening(getActivity()))
    //         return;

    // 2013-12-10
    // ?  .
    if (UiUtil.isSlidingMenuOpening(getActivity()))
        UiUtil.toggleSidebar(getActivity());

    switch (v.getId()) {
    case R.id.vod_zzim:
        // test wifi status
        //boolean b = Util.setWifiEnable(getActivity(), false);

        // wifi check
        if (!Util.isWifiAvailable(getActivity())) {
            Toast.makeText(getActivity(), "WiFi not Available", Toast.LENGTH_SHORT).show();
            break;
        }

        // STB alive check
        pref = CnmPreferences.getInstance();
        hostAddress = pref.loadPairingHostAddress(getActivity());

        // test
        //hostAddress = "192.168.0.6";

        try {
            if (hostAddress.equals("")) {
                //   10 .
                Log.d("hwang", "vod  : db insert");
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                PopupGtvNotAlive gtvNotAlive = PopupGtvNotAlive.newInstance(vodAssetId);
                gtvNotAlive.show(ft, PopupGtvNotAlive.class.getSimpleName());
                break;
            } else {

                InetAddress address = InetAddress.getByName(hostAddress);
                boolean alive = address.isReachable(2000);

                if (alive) {
                    if (startJobVodJjim) {
                        Log.d("hwang", "don't send again");
                        break; //  ?      ??!!!
                    }
                    startJobVodJjim = true;

                    Log.d("hwang", "send vod ");
                    mVodJjimMainHandler = new VodJjimSendMassgeHandler();

                    // if 0, just send
                    Cursor cursor = getActivity().getContentResolver().query(VodJjim.CONTENT_URI, null, null,
                            null, null);
                    if (cursor != null) {
                        if (cursor.getCount() == 0) {
                            //  .
                            vodJjimFromDb = false;
                            TCPClientVod tcpVodClient = new TCPClientVod(mVodJjimMainHandler, hostAddress,
                                    vodAssetId);
                            tcpVodClient.start();

                        } else { // ?
                            // prepairing for send-loop
                            vodJjimFromDb = true;
                            getActivity().getContentResolver().registerContentObserver(VodJjim.CONTENT_URI,
                                    true, observer);

                            // db insert
                            Util.insertDBVodJjim(getActivity(), vodAssetId); // db insert

                        }
                    }
                    cursor.close();
                    break;
                } else {
                    //   10 .
                    Log.d("hwang", "vod  : db insert");
                    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                    PopupGtvNotAlive gtvNotAlive = PopupGtvNotAlive.newInstance(vodAssetId);
                    gtvNotAlive.show(ft, PopupGtvNotAlive.class.getSimpleName());
                    break;
                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        break;

    case R.id.vod_tv_watching:
        // wifi check
        if (!Util.isWifiAvailable(getActivity())) {
            Toast.makeText(getActivity(), "WiFi not Available", Toast.LENGTH_SHORT).show();
            break;
        }

        // STB alive check
        pref = CnmPreferences.getInstance();
        hostAddress = pref.loadPairingHostAddress(getActivity());

        // test
        //hostAddress = "192.168.0.6";

        try {
            if (hostAddress.equals("")) {
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                PopupGtvNotAliveTv gtvNotAlive = new PopupGtvNotAliveTv();
                gtvNotAlive.show(ft, PopupGtvNotAliveTv.class.getSimpleName());
                break;
            } else {

                InetAddress address = InetAddress.getByName(hostAddress);
                boolean alive = address.isReachable(2000);
                if (alive) {
                    if (startJobTv) {
                        Log.d("hwang", "don't send again");
                        break; //  ?      ??!!!
                    }
                    startJobTv = true;

                    mTvMainHandler = new TvSendMassgeHandler();

                    TCPClientTv tcpTvClient = new TCPClientTv(mTvMainHandler, hostAddress, vodAssetId);
                    tcpTvClient.start();
                    break;
                } else {
                    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                    PopupGtvNotAliveTv gtvNotAlive = new PopupGtvNotAliveTv();
                    gtvNotAlive.show(ft, PopupGtvNotAlive.class.getSimpleName());
                    break;

                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        break;
    }
}

From source file:ezbake.IntentQuery.Sample.MongoDatasource.Server.MongoExternalDataSourceHandler.java

public MongoExternalDataSourceHandler() {
    //tableOpenIdentity_to_handle_Map = new HashMap<TableOpenIdentity, String>();
    //handle_to_offset_Map = new HashMap<String, Integer>();

    table_scan_status_map = new HashMap<String, TableScanStatus>();

    // read table metadata into private Map<String, TableMetadata>   table_metadata_map;
    parseDataSourceMetadata();//  w  w w  .  j  a  v a  2s .  co  m
    System.out.println(String.format("Total %d tables metadata loaded.", table_metadata_map.size()));

    try {
        /*
        Configuration   propertiesConfig = new PropertiesConfiguration(impalaDsPropertiesFile);
                
        dbHost = propertiesConfig.getString("mongodb.host.name");
        dbPort = propertiesConfig.getInt("mongodb.port");
        dbName = propertiesConfig.getString("mongodb.database.name");
        */

        mongoClient = new MongoClient(dbHost, dbPort);
        mongoDb = mongoClient.getDB(dbName);

        System.out.println("dbHost = " + dbHost);
        System.out.println("dbPort = " + dbPort);
        System.out.println("dbName = " + dbName);

    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}