Example usage for java.rmi.server UID UID

List of usage examples for java.rmi.server UID UID

Introduction

In this page you can find the example usage for java.rmi.server UID UID.

Prototype

public UID() 

Source Link

Document

Generates a UID that is unique over time with respect to the host that it was generated on.

Usage

From source file:org.openmobster.core.common.Utilities.java

/**
 * Randomly generates a unique identifier
 * /* w  w w. ja  va2  s . c o  m*/
 * @return the unique identifier
 */
public static String generateUID() {
    String uid = null;

    UID cour = new UID();
    uid = String.valueOf(cour.toString());

    return uid;
}

From source file:org.moonwave.util.UUID.java

/**
 * Returns a uuid based on java.rmi.server.UID
 * @return//w  w w .java2 s.  c o m
 */
public static String newId() {
    UID uid = new UID();
    String uuid = uid.toString();
    uuid = StringUtils.replace(uuid, ":", "");
    uuid = StringUtils.replace(uuid, "-", "");
    return uuid;
}

From source file:UuidUtil.java

public static String generateUuidMM() {
    return new StringBuffer(new UID().toString()).reverse().append(':').append(_inetAddr).toString();
}

From source file:org.mobicents.slee.resource.tftp.events.RequestEventImpl.java

public RequestEventImpl(TFTPPacket req, TFTPTransfer source) {
    super(source);
    this.req = req;
    this.tt = source;
    this.id = new UID().toString();
}

From source file:ru.ksu.niimm.cll.mocassin.util.StringUtil.java

/**
 * Generates an identifier that is unique over time with respect to the host
 * that it was generated on. Used approach is similar to Jena's.
 * /* w  w w.java2 s  . c  om*/
 * 
 * @return
 */
public static String generateBlankNodeId() {
    return format("_:bnode%d", new UID().hashCode());
}

From source file:edumsg.core.commands.user.LoginCommand.java

@Override
public void execute() {

    try {//from w  w  w.ja v a  2  s  .  com
        String sessionID = URLEncoder.encode(new UID().toString(), "UTF-8");
        String cleaned_session = sessionID.replace("%", "\\%");
        dbConn = PostgresConnection.getDataSource().getConnection();
        dbConn.setAutoCommit(false);
        proc = dbConn.prepareCall("{? = call get_password_info(?)}");
        proc.setPoolable(true);
        proc.registerOutParameter(1, Types.VARCHAR);
        proc.setString(2, map.get("username"));
        proc.execute();

        String enc_password = proc.getString(1);

        if (enc_password == null) {
            CommandsHelp.handleError(map.get("app"), map.get("method"), "Invalid username",
                    map.get("correlation_id"), LOGGER);
            return;
        }

        proc.close();
        dbConn.commit();

        boolean authenticated = BCrypt.checkpw(map.get("password"), enc_password);

        if (authenticated) {
            User user = new User();
            Statement query = dbConn.createStatement();

            //                query = dbConn.createStatement();
            //                query.setPoolable(true);
            //                set = query.executeQuery(String.format("SELECT * FROM login('%s','%s')"
            //                        , map.get("username")
            //                        , cleaned_session));

            proc = dbConn.prepareCall("{? = call login(?,?)}");
            proc.setPoolable(true);
            proc.registerOutParameter(1, Types.OTHER);
            proc.setString(2, map.get("username"));
            proc.setString(3, cleaned_session);
            proc.execute();
            set = (ResultSet) proc.getObject(1);

            root.put("app", map.get("app"));
            root.put("method", map.get("method"));
            root.put("status", "ok");
            root.put("code", "200");

            while (set.next()) {
                id = set.getInt("id");
                username = set.getString("username");
                email = set.getString("email");
                name = set.getString("name");
                language = set.getString("language");
                country = set.getString("country");
                bio = set.getString("bio");
                website = set.getString("website");
                created_at = set.getTimestamp("created_at");
                avatar_url = set.getString("avatar_url");
                overlay = set.getBoolean("overlay");
                link_color = set.getString("link_color");
                background_color = set.getString("background_color");
                protected_tweets = set.getBoolean("protected_tweets");

                user.setUsername(username);
                user.setEmail(email);
                user.setName(name);
                user.setLanguage(language);
                user.setCountry(country);
                user.setBio(bio);
                user.setWebsite(website);
                user.setCreatedAt(created_at);
                user.setAvatarUrl(avatar_url);
                user.setOverlay(overlay);
                user.setLinkColor(link_color);
                user.setBackgroundColor(background_color);
                user.setProtectedTweets(protected_tweets);
                user.setSessionID(sessionID);

                details = new HashMap<String, String>();

                details.put("id", id.toString());
                details.put("username", username);
                details.put("email", email);
                details.put("name", name);
                details.put("language", language);
                details.put("country", country);
                details.put("bio", bio);
                details.put("website", website);
                details.put("created_at", created_at.toString());
                details.put("avatar_url", avatar_url);
                details.put("overlay", overlay.toString());
                details.put("link_color", link_color);
                details.put("background_color", background_color);
                details.put("protected_tweets", protected_tweets.toString());
                details.put("session_id", sessionID);
            }

            proc.close();
            dbConn.commit();

            user.setSessionID(cleaned_session);
            UserCache.cacheUser(id.toString(), details);
            UserCache.mapUsernameID(username, id + "");
            UserCache.cacheUserSession(cleaned_session, details.get("id"));

            ValueNode child = nf.pojoNode(user);
            root.set("user", child);

            try {
                CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"),
                        LOGGER);
            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {
            CommandsHelp.handleError(map.get("app"), map.get("method"), "Invalid Password",
                    map.get("correlation_id"), LOGGER);
        }

    } catch (PSQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        //Logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (SQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        //Logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        //Logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (Exception e) {
        e.printStackTrace();
        //Logger.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        PostgresConnection.disconnect(set, proc, dbConn, null);
    }
}

From source file:org.apache.camel.component.javaspace.JavaSpaceProducer.java

public void process(Exchange exchange) throws Exception {
    Entry entry;// w  w  w .  j a va 2  s . c  o m
    Object body = exchange.getIn().getBody();

    if (!(body instanceof Entry)) {
        entry = new InEntry();

        if (body instanceof BeanInvocation) {
            ((InEntry) entry).correlationId = (new UID()).toString();
        }

        if (body instanceof byte[]) {
            ((InEntry) entry).binary = true;
            ((InEntry) entry).buffer = (byte[]) body;
        } else {
            ((InEntry) entry).binary = false;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(body);
            ((InEntry) entry).buffer = bos.toByteArray();
        }
    } else {
        entry = (Entry) body;
    }

    if (entry == null) {
        LOG.warn("No payload for exchange: " + exchange);
    } else {
        Transaction tnx = null;
        if (transactionHelper != null) {
            tnx = transactionHelper.getJiniTransaction(transactionTimeout).transaction;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Writing body : " + entry);
        }
        javaSpace.write(entry, tnx, Lease.FOREVER);

        if (ExchangeHelper.isOutCapable(exchange)) {
            OutEntry tmpl = new OutEntry();
            tmpl.correlationId = ((InEntry) entry).correlationId;

            OutEntry replyCamelEntry = null;
            while (replyCamelEntry == null) {
                replyCamelEntry = (OutEntry) javaSpace.take(tmpl, tnx, 100);
            }

            Object obj;
            if (replyCamelEntry.binary) {
                obj = replyCamelEntry.buffer;
            } else {
                ByteArrayInputStream bis = new ByteArrayInputStream(replyCamelEntry.buffer);
                ObjectInputStream ois = new ObjectInputStream(bis);
                obj = ois.readObject();
            }
            exchange.getOut().setBody(obj);
        }
        if (tnx != null) {
            tnx.commit();
        }
    }
}

From source file:gov.nih.nci.caarray.application.fileaccess.TemporaryFileCacheImpl.java

private void createSessionWorkingDirectory() {
    final String sessionSubdirectoryName = new UID().toString().replace(':', '_').replace('-', '_');
    this.sessionWorkingDirectory = new File(getWorkingDirectory(), sessionSubdirectoryName);
    if (!this.sessionWorkingDirectory.mkdirs()) {
        LOG.error("Couldn't create directory: " + this.sessionWorkingDirectory.getAbsolutePath());
        throw new IllegalStateException(
                "Couldn't create directory: " + this.sessionWorkingDirectory.getAbsolutePath());
    }/*from  w  w w  .ja va 2 s  .co m*/
}

From source file:org.ajax4jsf.request.FileParam.java

public File createTempFile() {
    try {//www . ja  v  a 2 s  . c  om
        tempFile = File.createTempFile(new UID().toString().replace(":", "-"), ".upload");
        fOut = new FileOutputStream(tempFile);
    } catch (IOException ex) {
        if (fOut != null) {
            try {
                fOut.close();
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        }

        throw new FileUploadException("Could not create temporary file");
    }
    return tempFile;
}

From source file:nl.nn.adapterframework.util.Misc.java

/**
* Creates a Universally Unique Identifier, via the java.rmi.server.UID class.
*//*from  w w w. j a  v a  2  s .co  m*/
public static String createSimpleUUID() {
    UID uid = new UID();

    String uidString = asHex(getIPAddress()) + "-" + uid.toString();
    // Replace semi colons by underscores, so IBIS will support it
    uidString = uidString.replace(':', '_');
    return uidString;
}