Example usage for java.util.logging Level WARNING

List of usage examples for java.util.logging Level WARNING

Introduction

In this page you can find the example usage for java.util.logging Level WARNING.

Prototype

Level WARNING

To view the source code for java.util.logging Level WARNING.

Click Source Link

Document

WARNING is a message level indicating a potential problem.

Usage

From source file:Classes.Database.java

/**
 * Makes a save SQL statement and executes it
 *
 * @param sql       The query, use an "?" at the place of a input. Like this:
 *                  INSERT INTO TABLE('name', 'lastname' , enz ) VALUES(?,?, enz);
 * @param arguments The arguments correspont to same questionmark.
 * @return The generated key/*from  w  ww.j  av  a 2s  .co m*/
 * @throws SQLException
 */
public Integer setDatabase(String sql, Object... arguments) {
    Connection conn = null;
    PreparedStatement psta = null;
    ResultSet rs = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection(url, username, password);
        psta = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

        EscapeSQL(psta, arguments);

        psta.executeUpdate();
        rs = psta.getGeneratedKeys();
        if (rs != null && rs.next()) {
            if (rs.getInt(1) == 0) { //maybe errors
                return -1;
            }
            return rs.getInt(1);
        }
        return -1;
    } catch (SQLException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "SQL Error: " + e.getMessage(), e);
        return -1;
    } catch (ClassNotFoundException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "Class Error " + e.getMessage(), e);
        return -1;
    } finally {
        if (conn != null) {
            //close and commit
            Logger.getAnonymousLogger().log(Level.INFO, "Commit" + sql);
            try {
                conn.commit();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
            try {
                conn.close();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
        }

        if (psta != null) {
            try {
                psta.close();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
        }

        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
        }
    }
}

From source file:bizlogic.Command.java

public static int Process(String _command, Connection con, PrintWriter out) throws SQLException {

    try {//from   w w w . ja v a  2s. c om
        System.out.print("Processing command: ");
        System.out.println(_command);

        String string = _command;
        String[] _array = string.split(",");

        String command = _array[0];

        switch (command) {
        case "addSensor":
            bizlogic.Sensors.add(con, _array[1], _array[2], _array[3], _array[4], _array[5], _array[6]);
            bizlogic.Sensors.list(con);
            break;

        case "delSensor":
            bizlogic.Sensors.del(con, _array[1]);
            bizlogic.Sensors.list(con);
            break;

        case "listSensors":
            bizlogic.Sensors.list(con);
            out.println("sensors.json ok");
            break;

        case "addRecord":
            bizlogic.Records.add(con, _array[1], _array[2], _array[3], _array[4]);
            bizlogic.Records.list(con);
            break;

        case "delRecord":
            bizlogic.Records.del(con, _array[1]);
            bizlogic.Records.list(con);
            break;

        case "startRecords":
            bizlogic.Records.setColumn(con, _array[1], "USERCONF.LOG_LIST", "RUNNING", "true");
            // (conDB, records, column, value)
            //bizlogic.Records.list(con);
            out.println("startRecords " + _array[1]);
            break;

        case "stopRecords":
            bizlogic.Records.setColumn(con, _array[1], "USERCONF.LOG_LIST", "RUNNING", "false");
            // (conDB, records, column, value)
            //bizlogic.Records.list(con);
            out.println("stopRecords " + _array[1]);
            break;

        case "listRecords":
            bizlogic.Records.list(con);
            out.println("listRecords ok");
            break;

        case "writeCSV":
            bizlogic.Records.writeCSV(con, _array[1]);
            out.println("writeCSV " + _array[1] + " Value" + " Time");
            break;

        case "setConf":
            String[] confString = new String[] { "date", "+%D", "--set", _array[3] + " " + _array[2] };
            System.out.println("confString=" + Arrays.toString(confString));
            Process p = java.lang.Runtime.getRuntime().exec(confString);
            int setConf_status = p.waitFor();
            System.out.println("confStatus = " + Integer.toString(setConf_status));
            if (setConf_status != -1) {
                out.println("setConf " + "ok");
            } else {
                out.println("ERROR Date not set");
            }
            break;

        case "serverTime":
            DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Date date = new Date(System.currentTimeMillis());
            out.println("Server time: " + sdf.format(date));
            break;

        case "changeIP":

            if (bizlogic.modSettings.validateIP(_array[1])) {
                System.out.println("changeIP to " + _array[1]);
                bizlogic.modSettings.resetIP();
                if (!_array[1].equals("0.0.0.0")) {
                    bizlogic.modSettings.setIP(_array[1]);
                }
                out.println("Server rebooting to set the IP");
                out.close();
                con.close();
                java.lang.Runtime.getRuntime().exec("sudo reboot");
            } else {
                out.println("ERROR: Bad IP address." + " Enter a valid IPv4 addess");
                System.out.println("Bad IP: " + _array[1]);
                java.lang.Runtime.getRuntime().exec(
                        "pid2=`ps aux | " + "grep \"[d]l_hwlogic\" | awk '{print $2}'`\n" + "kill -9 $pid2");
            }
            break;

        default:
            break;
        }
        return 1;
    } catch (IOException | ParseException | InterruptedException ex) {
        Logger.getLogger(Command.class.getName()).log(Level.WARNING, null, ex);
        return -1;
    }
}

From source file:de.flapdoodle.embed.redis.RedisDProcess.java

public static boolean shutdownRedis(AbstractRedisConfig config) {
    try {//  w  w w.  j a va 2  s . co  m
        // ensure that we don't get into a stackoverflow when starting
        // the artifact fails entirely
        if (config.isNested()) {
            logger.log(Level.INFO, "Nested stop, won't execute redis process again");
            return false;
        }
        InetAddress host = config.net().getServerAddress();
        int port = config.net().getPort();
        if (!host.isLoopbackAddress()) {
            logger.log(Level.WARNING,
                    "" + "---------------------------------------\n" + "Your localhost ("
                            + host.getHostAddress() + ") is not a loopback adress\n"
                            + "We can NOT send shutdown to redis, because it is denied from remote."
                            + "---------------------------------------\n");
            return false;
        }
        try {
            Jedis j = new Jedis(host.getHostName(), port);
            String reply = j.shutdown();
            if (StringUtils.isEmpty(reply)) {
                return true;
            } else {
                logger.log(Level.SEVERE, String
                        .format("sendShutdown closing %s:%s; Got response from server %s", host, port, reply));
                return false;
            }
        } catch (JedisConnectionException e) {
            logger.log(Level.WARNING,
                    String.format("sendShutdown closing %s:%s. No Service listening on address.\n%s", host,
                            port, e.getMessage()));
            return true;
        }
    } catch (UnknownHostException e) {
        logger.log(Level.SEVERE, "sendStop", e);
    }
    return false;
}

From source file:com.avaje.ebean.springsupport.txn.SpringAwareJdbcTransactionManager.java

/**
 * Looks for a current Spring managed transaction and wraps/returns that as a Ebean transaction.
 * <p>//  w  ww.  j ava  2s.c  o  m
 * Returns null if there is no current spring transaction (lazy loading outside a spring txn etc).
 * </p>
 */
public Object getCurrentTransaction() {

    // Get the current Spring ConnectionHolder associated to the current spring managed transaction
    ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);

    if (holder == null || !holder.isSynchronizedWithTransaction()) {
        // no current Spring transaction
        SpiTransaction currentEbeanTransaction = DefaultTransactionThreadLocal.get(serverName);
        if (currentEbeanTransaction != null) {
            // NOT expecting this so log WARNING
            String msg = "SpringTransaction - no current spring txn BUT using current Ebean one "
                    + currentEbeanTransaction.getId();
            logger.log(Level.WARNING, msg);

        } else if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, "Spring Txn - no current transaction ");
        }
        return currentEbeanTransaction;
    }

    SpringTxnListener springTxnLister = getSpringTxnListener();

    if (springTxnLister != null) {
        // we have already seen this transaction 
        return springTxnLister.getTransaction();

    } else {
        // This is a new spring transaction that we have not seen before.
        // "wrap" it in a SpringJdbcTransaction for use with Ebean 
        SpringJdbcTransaction newTrans = new SpringJdbcTransaction(holder, transactionManager);

        // Create and register a Spring TransactionSynchronization for this transaction
        springTxnLister = createSpringTxnListener(newTrans);
        TransactionSynchronizationManager.registerSynchronization(springTxnLister);

        // also put in Ebean ThreadLocal
        DefaultTransactionThreadLocal.set(serverName, newTrans);
        return newTrans;
    }
}

From source file:ca.sfu.federation.model.Behavior.java

/**
 * Set the update condition rule.//from w ww .java 2 s.c  o m
 * @param Condition Update condition rule.
 */
public void setUpdateCondition(String Condition) {
    try {
        this.selection = new Selection(Condition, this.context);
    } catch (MalformedSelectionRuleException ex) {
        String stack = ExceptionUtils.getFullStackTrace(ex);
        logger.log(Level.WARNING, "Malformed selection rule\n\n{0}", stack);
    }
}

From source file:com.alehuo.wepas2016projekti.controller.ImageController.java

/**
 * Hakee tietokannasta kuvan. Kuvan hakemisessa hydynnetn ETag
 * -otsaketta./*from w  w  w .java2  s.co m*/
 *
 * @param a Autentikointi
 * @param imageUuid Kuvan UUID
 * @param ifNoneMatch If-None-Match -headeri vlimuistia varten
 * @return Kuva
 */
@RequestMapping(value = "/{imageUuid}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<byte[]> getImage(Authentication a, @PathVariable String imageUuid,
        @RequestHeader(required = false, value = "If-None-Match") String ifNoneMatch) {
    if (ifNoneMatch != null) {
        //            LOG.log(Level.INFO, "Kuva ''{0}'' loytyy kayttajan selaimen valimuistista eika sita tarvitse ladata. Kuvaa pyysi kayttaja ''{1}''", new Object[]{imageUuid, a.getName()});
        //Jos If-None-Match -headeri lytyy, niin lhet NOT MODIFIED vastaus
        return new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
    }
    Image i = imageService.findOneImageByUuid(imageUuid);
    if (i != null && i.isVisible()) {
        //Luodaan ETag kuvalle
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType(i.getContentType()));
        headers.setContentLength(i.getImageData().length);
        headers.setCacheControl("public");
        headers.setExpires(Long.MAX_VALUE);
        headers.setETag("\"" + imageUuid + "\"");
        //            LOG.log(Level.INFO, "Kuva ''{0}'' loytyi tietokannasta, ja sita pyysi kayttaja ''{1}''", new Object[]{imageUuid, a.getName()});
        //Palautetaan kuva uutena resurssina
        return new ResponseEntity<>(i.getImageData(), headers, HttpStatus.CREATED);
    } else {
        //Jos kuvaa ei lydy tietokannasta
        LOG.log(Level.WARNING, "Kuvaa ''{0}'' ei loytynyt tietokannasta, ja sita pyysi kayttaja ''{1}''",
                new Object[] { imageUuid, a.getName() });
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.github.cc007.headsinventory.search.HeadsSearch.java

public static void saveHead(Player player, String headName) {
    Translator t = HeadsInventory.getTranslator();
    Head newHead = null;//from  w  w w. java2 s  .  c  om
    try {
        HeadsUtils hu = HeadsUtils.getInstance();
        hu.setDatabaseLoader(new MineSkinLoader());
        newHead = hu.saveHead(player, headName);
        hu.setDatabaseLoader(HeadsPlugin.getDefaultDatabaseLoader());
    } catch (SocketTimeoutException ex) {
        Bukkit.getLogger().log(Level.SEVERE, ex.getMessage());
        player.sendMessage(
                HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-sockettimeout"));
        return;
    } catch (MalformedURLException ex) {
        // prob no heads found
        Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-malformedurl"), ex);
    } catch (UnknownHostException ex) {
        Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-unknownhost"), ex);
    } catch (IOException ex) {
        Bukkit.getLogger().log(Level.SEVERE, null, ex);
        player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-io"));
        return;
    } catch (AuthenticationException ex) {
        //legacy exception
        Bukkit.getLogger().log(Level.SEVERE, null, ex);
        return;
    }
    if (newHead == null) {
        player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.RED
                + t.getText("search-error-addhead-failure"));
        return;
    }
    ItemStack newHeadStack = HeadCreator.getItemStack(newHead);
    putHeadInInventory(newHeadStack, player);
    player.sendMessage(HeadsInventory.pluginChatPrefix(true) + t.getText("search-error-addhead-success"));
}

From source file:edu.umass.cs.msocket.proxy.GnsTimerKeepalive.java

/**
 * @see java.lang.Thread#run()/*from ww  w  .  j av  a2s . co m*/
 */
@Override
public void run() {
    long last = System.currentTimeMillis();
    while (!killed) {
        long sleepFor = last + publishFrequency - System.currentTimeMillis();
        if (sleepFor > 0)
            try {
                Thread.sleep(sleepFor);
            } catch (InterruptedException ignore) {
            }

        last = System.currentTimeMillis();
        try {
            gnsCredentials.getGnsClient().fieldReplace(guid.getGuid(), GnsConstants.CURRENT_TIME,
                    new JSONArray().put(last), guid);
            logger.fine("Updated current time to " + last);
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed to update CURRENT_TIME with " + last, e);
        }
    }
}

From source file:com.almende.eve.state.couchdb.CouchDBState.java

@Override
public synchronized boolean locPutIfUnchanged(final String key, final JsonNode newVal, JsonNode oldVal) {
    final String ckey = couchify(key);
    boolean result = false;
    try {//  ww  w .  j a  v  a2  s.c o m
        JsonNode cur = NullNode.getInstance();
        if (properties.containsKey(ckey)) {
            cur = properties.get(ckey);
        }
        if (oldVal == null) {
            oldVal = NullNode.getInstance();
        }

        // Poor mans equality as some Numbers are compared incorrectly: e.g.
        // IntNode versus LongNode
        if (oldVal.equals(cur) || oldVal.toString().equals(cur.toString())) {
            properties.put(ckey, newVal);
            update();
            result = true;
        }
    } catch (final UpdateConflictException uce) {
        read();
        return locPutIfUnchanged(ckey, newVal, oldVal);
    } catch (final Exception e) {
        LOG.log(Level.WARNING, "", e);
    }

    return result;
}

From source file:com.tckb.geo.stubgen.Generator.java

/**
 * Retrieves the raw data response from the webservice
 *
 * @param r//from   w ww.j  a v  a 2s .  c o  m
 * @return
 * @throws IOException
 */
public static String getRawData(Response r) throws IOException {
    Logger.getAnonymousLogger().log(Level.INFO, "Retrieving raw data from remote url: {0}", r.getUrl());
    if (r.getStatus() == 200) {
        BufferedReader br = new BufferedReader(new InputStreamReader(r.getBody().in()));
        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        return sb.toString();
    } else {
        Logger.getAnonymousLogger().log(Level.WARNING, "Server returned {0} status while retrieving{1} !",
                new Object[] { String.valueOf(r.getStatus()), r.getUrl() });
        return "_NO_CONTENT_";
    }
}