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.geoserver.notification.geonode.GeoNodeJsonEncoder.java

@Override
public byte[] encode(Notification notification) throws Exception {
    byte[] ret = null;

    ObjectMapper mapper = new ObjectMapper();
    mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"));
    mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setSerializationInclusion(Include.NON_NULL);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    KombuMessage message = new KombuMessage();

    message.setId(new UID().toString());
    message.setType(notification.getType() != null ? notification.getType().name() : null);
    message.setAction(notification.getAction() != null ? notification.getAction().name() : null);
    message.setTimestamp(new Date());
    message.setUser(notification.getUser());
    message.setOriginator(InetAddress.getLocalHost().getHostAddress());
    message.setProperties(notification.getProperties());
    if (notification.getObject() instanceof NamespaceInfo) {
        NamespaceInfo obj = (NamespaceInfo) notification.getObject();
        KombuNamespaceInfo source = new KombuNamespaceInfo();
        source.setId(obj.getId());//from ww  w . j  a  v a  2s .c o  m
        source.setType("NamespaceInfo");
        source.setName(obj.getName());
        source.setNamespaceURI(obj.getURI());
        message.setSource(source);
    }
    if (notification.getObject() instanceof WorkspaceInfo) {
        WorkspaceInfo obj = (WorkspaceInfo) notification.getObject();
        KombuWorkspaceInfo source = new KombuWorkspaceInfo();
        source.setId(obj.getId());
        source.setType("WorkspaceInfo");
        source.setName(obj.getName());
        source.setNamespaceURI("");
        message.setSource(source);
    }
    if (notification.getObject() instanceof LayerInfo) {
        LayerInfo obj = (LayerInfo) notification.getObject();
        KombuLayerInfo source = new KombuLayerInfo();
        source.setId(obj.getId());
        source.setType("LayerInfo");
        source.setName(obj.getName());
        source.setResourceType(obj.getType() != null ? obj.getType().name() : "");
        BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer("name");
        Collection<String> styleNames = CollectionUtils.collect(obj.getStyles(), transformer);
        source.setStyles(StringUtils.join(styleNames.toArray()));
        source.setDefaultStyle(obj.getDefaultStyle() != null ? obj.getDefaultStyle().getName() : "");
        ResourceInfo res = obj.getResource();
        source.setWorkspace(res.getStore() != null
                ? res.getStore().getWorkspace() != null ? res.getStore().getWorkspace().getName() : ""
                : "");
        if (res.getNativeBoundingBox() != null) {
            source.setBounds(new Bounds(res.getNativeBoundingBox()));
        }
        if (res.getLatLonBoundingBox() != null) {
            source.setGeographicBunds(new Bounds(res.getLatLonBoundingBox()));
        }
        message.setSource(source);
    }
    if (notification.getObject() instanceof LayerGroupInfo) {
        LayerGroupInfo obj = (LayerGroupInfo) notification.getObject();
        KombuLayerGroupInfo source = new KombuLayerGroupInfo();
        source.setId(obj.getId());
        source.setType("LayerGroupInfo");
        source.setName(obj.getName());
        source.setWorkspace(obj.getWorkspace() != null ? obj.getWorkspace().getName() : "");
        source.setMode(obj.getType().name());
        String rootStyle = obj.getRootLayerStyle() != null ? obj.getRootLayerStyle().getName() : "";
        source.setRootLayerStyle(rootStyle);
        source.setRootLayer(obj.getRootLayer() != null ? obj.getRootLayer().getPath() : "");
        for (PublishedInfo pl : obj.getLayers()) {
            KombuLayerSimpleInfo kl = new KombuLayerSimpleInfo();
            if (pl instanceof LayerInfo) {
                LayerInfo li = (LayerInfo) pl;
                kl.setName(li.getName());
                String lstyle = li.getDefaultStyle() != null ? li.getDefaultStyle().getName() : "";
                if (!lstyle.equals(rootStyle)) {
                    kl.setStyle(lstyle);
                }
                source.addLayer(kl);
            }
        }
        message.setSource(source);
    }
    if (notification.getObject() instanceof ResourceInfo) {
        ResourceInfo obj = (ResourceInfo) notification.getObject();
        KombuResourceInfo source = null;
        if (notification.getObject() instanceof FeatureTypeInfo) {
            source = new KombuFeatureTypeInfo();
            source.setType("FeatureTypeInfo");
        }
        if (notification.getObject() instanceof CoverageInfo) {
            source = new KombuCoverageInfo();
            source.setType("CoverageInfo");
        }
        if (notification.getObject() instanceof WMSLayerInfo) {
            source = new KombuWMSLayerInfo();
            source.setType("WMSLayerInfo");
        }
        if (source != null) {
            source.setId(obj.getId());
            source.setName(obj.getName());
            source.setWorkspace(obj.getStore() != null
                    ? obj.getStore().getWorkspace() != null ? obj.getStore().getWorkspace().getName() : ""
                    : "");
            source.setNativeName(obj.getNativeName());
            source.setStore(obj.getStore() != null ? obj.getStore().getName() : "");
            if (obj.getNativeBoundingBox() != null) {
                source.setGeographicBunds(new Bounds(obj.getNativeBoundingBox()));
            }
            if (obj.boundingBox() != null) {
                source.setBounds(new Bounds(obj.boundingBox()));
            }
        }
        message.setSource(source);
    }
    if (notification.getObject() instanceof StoreInfo) {
        StoreInfo obj = (StoreInfo) notification.getObject();
        KombuStoreInfo source = new KombuStoreInfo();
        source.setId(obj.getId());
        source.setType("StoreInfo");
        source.setName(obj.getName());
        source.setWorkspace(obj.getWorkspace() != null ? obj.getWorkspace().getName() : "");
        message.setSource(source);
    }
    ret = mapper.writeValueAsBytes(message);
    return ret;

}

From source file:cx.jbzdak.diesIrae.genieConnector.ParamTest.java

@Test
public void testWriteChar() {
    String ident = new UID().toString().substring(0, 8);
    connector.setParam(ParamAlias.SAMPLE_IDENTIFIER, ident);
    Assert.assertEquals(ident, connector.getParam(ParamAlias.SAMPLE_IDENTIFIER));
}

From source file:com.legstar.pool.manager.ConnectionPool.java

/**
 * Construct a connection pool for an endpoint.
 * The connection pool is organized around a fixed size blocking queue.
 * Upon instantiation, all connections are created but not actually
 * connected to the host.//from   ww w.ja  v  a 2s .  c o m
 * 
 * @param address the target host address
 * @param hostEndpoint the target host endpoint
 * @throws ConnectionPoolException if pool cannot be created
 */
public ConnectionPool(final LegStarAddress address, final HostEndpoint hostEndpoint)
        throws ConnectionPoolException {

    _address = address;
    _hostEndpoint = hostEndpoint;

    int poolSize = hostEndpoint.getHostConnectionPoolSize();

    /* Create the blocking queue */
    _connections = new BlockingStack<LegStarConnection>(poolSize);

    /*
     * Create all connections with a unique ID each. This ID is used
     * for traceability. Because
     */
    try {
        for (int i = 0; i < poolSize; i++) {
            _connections.add(hostEndpoint.getHostConnectionfactory().createConnection(new UID().toString(),
                    address, hostEndpoint));
        }
    } catch (ConnectionException e) {
        throw new ConnectionPoolException(e);
    }
    _idleConnectionsPolicy = new TimerIdleConnectionsPolicy(this,
            hostEndpoint.getPooledMaxIdleTimeCheckPeriod(), hostEndpoint.getPooledMaxIdleTime());

    _shuttingDown = false;
    _log.info("Pool of size " + poolSize + ", created for endpoint: " + hostEndpoint.toString());
}

From source file:org.apache.hadoop.hive.ql.io.avro.AvroGenericRecordReader.java

public AvroGenericRecordReader(JobConf job, FileSplit split, Reporter reporter) throws IOException {
    this.jobConf = job;
    Schema latest;//from w w w  . j  av  a2  s. co m

    try {
        latest = getSchema(job, split);
    } catch (AvroSerdeException e) {
        throw new IOException(e);
    }

    GenericDatumReader<GenericRecord> gdr = new GenericDatumReader<GenericRecord>();

    if (latest != null) {
        gdr.setExpected(latest);
    }

    this.reader = new DataFileReader<GenericRecord>(new FsInput(split.getPath(), job), gdr);
    this.reader.sync(split.getStart());
    this.start = reader.tell();
    this.stop = split.getStart() + split.getLength();
    this.recordReaderID = new UID();
}

From source file:gov.nih.nci.caarray.services.external.v1_0.data.AbstractDataApiUtils.java

/**
 * {@inheritDoc}/*from  w w w  .  j a  v  a 2s.  co  m*/
 */
public File downloadFileContentsToTempDir(Iterable<CaArrayEntityReference> fileRefs)
        throws InvalidReferenceException, DataTransferException, IOException {
    String tempDirName = new UID().toString().replace(':', '_');
    File tempDir = new File(System.getProperty("java.io.tmpdir"), tempDirName);
    downloadFileContentsToDir(fileRefs, tempDir);
    return tempDir;
}

From source file:com.fusesource.forge.jmstest.tests.AsyncProducer.java

public String getReplyDestination() {
    if (replyDestination == null) {
        replyDestination = "queue:Reply." + getName() + "." + new UID().toString().hashCode();
        LOG.debug("Producer using replyTo Destination : " + replyDestination);
    }//  w  ww. j  a  v  a 2s.c om
    return replyDestination;
}

From source file:com.lucid.touchstone.data.LineDocMaker.java

public DocData setFields(String line) {
    // title <TAB> date <TAB> body <NEWLINE>
    final String title, date, body;

    int spot = line.indexOf(SEP);
    if (spot != -1) {
        title = line.substring(0, spot);
        int spot2 = line.indexOf(SEP, 1 + spot);
        if (spot2 != -1) {
            date = line.substring(1 + spot, spot2);
            body = line.substring(1 + spot2, getRandomNumber(1 + spot2 + 1, line.length()));
        } else//from   ww  w.ja v a 2 s.  co  m
            date = body = "";
    } else
        title = date = body = "";

    String id = new UID().toString();

    DocData doc = new DocData(ipAddr + id, body, title, date);
    return doc;

}

From source file:org.twdata.pkgscanner.InternalScanner.java

List<ExportPackage> findInPackageWithUrls(Test test, String packageName, Enumeration<URL> urls) {
    final List<ExportPackage> localExports = new ArrayList<ExportPackage>();

    final String tempDirName = new UID().toString().replace(':', '_').replace('-', '_');
    final File tempDir = new File(new File(System.getProperty("java.io.tmpdir")), tempDirName);
    if (!tempDir.mkdirs()) {
        throw new IllegalStateException("Couldn't create directory: " + tempDir.getAbsolutePath());
    }//from w w  w  .ja va 2  s .  co m

    while (urls.hasMoreElements()) {
        try {
            final URL url = urls.nextElement();
            String urlProtocol = url.getProtocol();
            String urlPath = url.getPath();

            log.debug("url = " + url.toString());
            log.debug("urlProtocol = " + urlProtocol);
            log.debug("Initial urlPath = " + urlPath);

            /*
             *  For any urls that match file:/path, replace file: with file://. Example below,
             *  url = jar:file:/C:/apps/local_install/jboss-5.1.0.GA-nci/lib/jboss-classloader.jar!/org
             *  urlProtocol = jar
             *  Initial urlPath = file:/C:/apps/local_install/jboss-5.1.0.GA-nci/lib/jboss-classloader.jar!/org
             */
            urlPath = urlPath.replace("file:", "file://");
            log.debug("After replacing with file://,  urlPath = " + urlPath);

            // special handling for jboss VFS - we cache the jar to a local copy, use it to do the scanning
            // as usual then discard it.
            // it's somewhat inefficient, but requires less rewriting of other parts of the code which make
            // assumptions that a JAR can be accessed as a file.
            // should consider eventually rewriting this to use jboss-vfs API directly for jar inspection
            // a possible starting point is http://community.jboss.org/message/8432
            if (urlProtocol.startsWith("vfs") && urlPath.contains(".jar")) {
                // Example:  url = vfszip:/C:/apps/local_install/jboss-5.1.0.GA-nci/lib/jboss-deployers-spi.jar/org/
                final String pathToJar = urlPath.substring(0, urlPath.lastIndexOf(".jar") + 4);
                final String jarName = pathToJar.substring(pathToJar.lastIndexOf("/") + 1, pathToJar.length());
                log.debug("pathToJar = " + pathToJar);
                log.debug("jarName = " + jarName);

                final File tmp = new File(tempDir, jarName);
                tmp.deleteOnExit();

                final URL jarUrl = new URL(url.getProtocol() + ":" + pathToJar);
                FileUtils.copyURLToFile(jarUrl, tmp);
                // append the file:// to the files absolute path, to make it a valid url.
                urlPath = "file://" + tmp.getAbsolutePath();
            } else if (urlPath.lastIndexOf('!') > 0) {
                // it's in a JAR, grab the path to the jar
                urlPath = urlPath.substring(0, urlPath.lastIndexOf('!'));
                if (urlPath.startsWith("/")) {
                    urlPath = "file://" + urlPath;
                }
            } else if (!urlPath.startsWith("file:")) {
                urlPath = "file://" + urlPath;
            }

            this.log.debug("Scanning for packages in [" + urlPath + "].");
            File file = null;
            final URL fileURL = new URL(urlPath);
            // only scan elements in the classpath that are local files
            if ("file".equals(fileURL.getProtocol().toLowerCase())) {
                log.debug("Protocol = file");
                String fileName = urlPath.substring("file://".length());
                // replace any %20 in the filename with spaces.
                fileName = fileName.replaceAll("%20", " ");
                log.debug("fileName = " + fileName);
                file = new File(fileName);
                log.debug("absolute file path = " + file.getAbsolutePath());

            } else {
                this.log.debug("Skipping non file classpath element [ " + urlPath + " ]");
            }

            if (file != null && file.isDirectory()) {
                localExports.addAll(loadImplementationsInDirectory(test, packageName, file));
            } else if (file != null) {
                if (test.matchesJar(file.getName())) {
                    localExports.addAll(loadImplementationsInJar(test, file));
                }
            }
        } catch (final IOException ioe) {
            this.log.error("could not read entries: " + ioe);
        }
    }
    FileUtils.deleteQuietly(tempDir);
    return localExports;
}

From source file:net.urlgrey.mythpodcaster.transcode.TranscodingControllerImpl.java

private void encodeUserDefined(TranscodingProfile profile, File inputFile, File outputFile) throws Exception {

    LOGGER.info("Starting user-defined encoding: inputFile[" + inputFile.getAbsolutePath() + "]");
    final File workingDirectory = FileOperations.createTempDir();

    try {//w w  w  . ja v  a  2  s.  c  o  m
        File tempInputFile = null;
        File tempOutputFile = null;
        final List<GenericTranscoderConfigurationItem> configItems = profile.getTranscoderConfigurationItems();
        for (GenericTranscoderConfigurationItem config : configItems) {
            if (tempOutputFile == null) {
                // first run, use the original input
                tempInputFile = inputFile;
            } else {
                // use the output from the previously executed command
                tempInputFile = tempOutputFile;
            }

            if (config.equals(configItems.get(configItems.size() - 1))) {
                tempOutputFile = File.createTempFile(new UID().toString(), profile.getEncodingFileExtension(),
                        workingDirectory);
            } else {
                tempOutputFile = File.createTempFile(new UID().toString(), "tmp", workingDirectory);
            }
            userDefinedTranscoder.transcode(workingDirectory, config, tempInputFile, tempOutputFile);
        }

        FileOperations.copy(tempOutputFile, outputFile);
    } finally {
        FileOperations.deleteDir(workingDirectory);
    }
}

From source file:net.unicon.academus.apps.download.DownloadServiceFileSystem.java

/**
 * Generate a globally unique identifier for the named resource.
 * @param name Name of the resource to generate an identifier for
 * @return A globally unique identifier for the named resource.
 *//* w  ww  . j av a 2s  .  c  o  m*/
private String generateIdentifier(String name) {
    StringBuffer rslt = new StringBuffer();

    // the UID class is guaranteed to be unique within the same host.
    // Coupled with a host unique identifier, it becomes globally unique.
    rslt.append(hostId).append('.');
    rslt.append(new UID().toString().replace(':', '.'));

    if (log.isDebugEnabled()) {
        log.debug("Resource '" + name + "' unique identifier: " + rslt);
    }
    return rslt.toString();
}