Example usage for java.lang System identityHashCode

List of usage examples for java.lang System identityHashCode

Introduction

In this page you can find the example usage for java.lang System identityHashCode.

Prototype

@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);

Source Link

Document

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().

Usage

From source file:de.metas.procurement.webui.LoggingConfiguration.java

public void updateMDC() {
    ///*w ww.  j a v  a  2s  . c om*/
    // Remote address
    try {
        final VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
        if (vaadinRequest != null) {
            final String remoteAddr = vaadinRequest.getRemoteAddr();
            MDC.put(MDC_Param_RemoteAddr, remoteAddr);
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_RemoteAddr, "?");
    }

    //
    // LoggedUser
    try {
        final MFSession mfSession = MFProcurementUI.getCurrentMFSession();
        if (mfSession != null) {
            final User user = mfSession.getUser();
            if (user != null) {
                final String email = user.getEmail();
                if (email != null) {
                    MDC.put(MDC_Param_LoggedUser, email);
                }
            }
        }

    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_LoggedUser, "?");
    }

    //
    // UserAgent
    try {
        final Page page = Page.getCurrent();
        if (page != null) {
            final WebBrowser webBrowser = page.getWebBrowser();
            if (webBrowser != null) {
                final String userAgent = webBrowser.getBrowserApplication();
                MDC.put(MDC_Param_UserAgent, userAgent);
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_UserAgent, "?");
    }

    //
    // SessionId
    try {
        final VaadinSession session = VaadinSession.getCurrent();
        if (session != null) {
            final int sessionId = System.identityHashCode(session);
            MDC.put(MDC_Param_SessionId, Integer.toString(sessionId));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_SessionId, "?");
    }

    //
    // UI Id
    try {
        final UI ui = UI.getCurrent();
        if (ui != null) {
            final int uiId = ui.getUIId();
            MDC.put(MDC_Param_UIId, Integer.toString(uiId));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_UIId, "?");
    }
}

From source file:org.envirocar.app.application.service.DeviceInRangeService.java

@Override
public void onDestroy() {
    logger.info("onDestroy " + getClass().getName() + "; Hash: " + System.identityHashCode(this));
    unregisterReceiver(receiver);/*from w w w . j  av a2 s.  c om*/

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notificationManager.cancel(BackgroundServiceImpl.BG_NOTIFICATION_ID);

    discoveryEnabled = false;
    discoveryHandler.removeCallbacks(discoveryRunnable);
}

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * @see java.applet.Applet#stop()/*from  ww  w .  j a v a  2  s .co  m*/
 */
@Override
public void stop() {
    for (final Receiver receiver : this.receiverMap.values())
        receiver.close();
    for (final Transmitter transmitter : this.transmitterMap.values())
        transmitter.close();
    for (final MidiDevice device : this.deviceMap.values())
        if (device.isOpen())
            device.close();
    this.deviceMap = null;
    this.receiverMap = null;
    this.transmitterMap = null;
    System.out.println("Stopped midi4js applet (Instance #" + System.identityHashCode(this) + ")");
}

From source file:org.compass.core.transaction.LocalTransaction.java

protected void doRollback() throws CompassException {
    if (session.getSearchEngine().wasRolledBack()) {
        // don't do anything, since it was rolled back already
    }/*from   w  ww . j a v a 2s  .co m*/

    if (state == UNKNOWN) {
        if (log.isDebugEnabled()) {
            log.debug("Rolling back local transaction, which exists within another local transaction "
                    + " on thread [" + Thread.currentThread().getName() + "] Compass ["
                    + System.identityHashCode(compass) + "] Session [" + System.identityHashCode(session)
                    + "]");
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Rolling back local transaction on thread [" + Thread.currentThread().getName()
                    + "] Compass [" + System.identityHashCode(compass) + "] Session ["
                    + System.identityHashCode(session) + "]");
        }

        ((LocalTransactionFactory) transactionFactory).unbindSessionFromTransaction(this, session);
    }

    state = ROLLBACK;
    session.evictAll();
    session.getSearchEngine().rollback();
}

From source file:gdsc.smlm.ij.plugins.DiffusionRateTest.java

public void run(String arg) {
    if (!showDialog())
        return;/*from  w w  w.  j a v  a 2 s . c  o m*/

    int totalSteps = settings.seconds * settings.stepsPerSecond;

    final double conversionFactor = 1000000.0 / (settings.pixelPitch * settings.pixelPitch);

    // Diffusion rate is um^2/sec. Convert to pixels per simulation frame.
    final double diffusionRateInPixelsPerSecond = settings.diffusionRate * conversionFactor;
    final double diffusionRateInPixelsPerStep = diffusionRateInPixelsPerSecond / settings.stepsPerSecond;

    Utils.log(TITLE + " : D = %s um^2/sec", Utils.rounded(settings.diffusionRate, 4));
    Utils.log("Mean-displacement per dimension = %s nm/sec",
            Utils.rounded(1e3 * ImageModel.getRandomMoveDistance(settings.diffusionRate), 4));

    // Convert diffusion co-efficient into the standard deviation for the random walk
    final double diffusionSigma = ImageModel.getRandomMoveDistance(diffusionRateInPixelsPerStep);
    Utils.log("Simulation step-size = %s nm", Utils.rounded(settings.pixelPitch * diffusionSigma, 4));

    // Move the molecules and get the diffusion rate
    IJ.showStatus("Simulating ...");
    final long start = System.nanoTime();
    RandomGenerator random = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
    Statistics[] stats2D = new Statistics[totalSteps];
    Statistics[] stats3D = new Statistics[totalSteps];
    for (int j = 0; j < totalSteps; j++) {
        stats2D[j] = new Statistics();
        stats3D[j] = new Statistics();
    }
    SphericalDistribution dist = new SphericalDistribution(settings.confinementRadius / settings.pixelPitch);
    Statistics asymptote = new Statistics();
    for (int i = 0; i < settings.particles; i++) {
        if (i % 16 == 0)
            IJ.showProgress(i, settings.particles);

        MoleculeModel m = new MoleculeModel(i, new double[3]);
        if (useConfinement) {
            // Note: When using confinement the average displacement should asymptote
            // at the average distance of a point from the centre of a ball. This is 3r/4.
            // See: http://answers.yahoo.com/question/index?qid=20090131162630AAMTUfM
            // The equivalent in 2D is 2r/3. However although we are plotting 2D distance
            // this is a projection of the 3D position onto the plane and so the particles
            // will not be evenly spread (there will be clustering at centre caused by the
            // poles)
            for (int j = 0; j < totalSteps; j++) {
                double[] xyz = m.getCoordinates();
                double[] originalXyz = Arrays.copyOf(xyz, 3);
                for (int n = confinementAttempts; n-- > 0;) {
                    if (settings.useGridWalk)
                        m.walk(diffusionSigma, random);
                    else
                        m.move(diffusionSigma, random);
                    if (!dist.isWithin(m.getCoordinates())) {
                        // Reset position
                        for (int k = 0; k < 3; k++)
                            xyz[k] = originalXyz[k];
                    } else {
                        // The move was allowed
                        break;
                    }
                }

                stats2D[j].add(squared(m.getCoordinates()));
                stats3D[j].add(distance2(m.getCoordinates()));
            }
            asymptote.add(distance(m.getCoordinates()));
        } else {
            if (settings.useGridWalk) {
                for (int j = 0; j < totalSteps; j++) {
                    m.walk(diffusionSigma, random);
                    stats2D[j].add(squared(m.getCoordinates()));
                    stats3D[j].add(distance2(m.getCoordinates()));
                }
            } else {
                for (int j = 0; j < totalSteps; j++) {
                    m.move(diffusionSigma, random);
                    stats2D[j].add(squared(m.getCoordinates()));
                    stats3D[j].add(distance2(m.getCoordinates()));
                }
            }
        }

        // Debug: record all the particles so they can be analysed
        // System.out.printf("%f %f %f\n", m.getX(), m.getY(), m.getZ());
    }
    final double time = (System.nanoTime() - start) / 1000000.0;

    IJ.showStatus("Analysing results ...");
    IJ.showProgress(1);

    if (showDiffusionExample) {
        showExample(totalSteps, diffusionSigma, random);
    }

    // Plot a graph of mean squared distance
    double[] xValues = new double[stats2D.length];
    double[] yValues2D = new double[stats2D.length];
    double[] yValues3D = new double[stats3D.length];
    double[] upper = new double[stats2D.length];
    double[] lower = new double[stats2D.length];
    final CurveFitter<Parametric> fitter2D = new CurveFitter<Parametric>(new LevenbergMarquardtOptimizer());
    final CurveFitter<Parametric> fitter3D = new CurveFitter<Parametric>(new LevenbergMarquardtOptimizer());
    Statistics gradient2D = new Statistics();
    Statistics gradient3D = new Statistics();
    final int firstN = (useConfinement) ? fitN : totalSteps;
    for (int j = 0; j < totalSteps; j++) {
        // Convert steps to seconds
        xValues[j] = (double) (j + 1) / settings.stepsPerSecond;

        // Convert values in pixels^2 to um^2
        final double mean = stats2D[j].getMean() / conversionFactor;
        final double sd = stats2D[j].getStandardDeviation() / conversionFactor;
        yValues2D[j] = mean;
        yValues3D[j] = stats3D[j].getMean() / conversionFactor;
        upper[j] = mean + sd;
        lower[j] = mean - sd;

        if (j < firstN) {
            fitter2D.addObservedPoint(xValues[j], yValues2D[j]);
            gradient2D.add(yValues2D[j] / xValues[j]);
            fitter3D.addObservedPoint(xValues[j], yValues3D[j]);
            gradient3D.add(yValues3D[j] / xValues[j]);
        }
    }

    // TODO - Fit using the equation for 2D confined diffusion:
    // MSD = 4s^2 + R^2 (1 - 0.99e^(-1.84^2 Dt / R^2)
    // s = localisation precision
    // R = confinement radius
    // D = 2D diffusion coefficient
    // t = time

    // Do linear regression to get diffusion rate
    final double[] init2D = { 0, 1 / gradient2D.getMean() }; // a - b x
    final double[] best2D = fitter2D.fit(new PolynomialFunction.Parametric(), init2D);
    final PolynomialFunction fitted2D = new PolynomialFunction(best2D);

    final double[] init3D = { 0, 1 / gradient3D.getMean() }; // a - b x
    final double[] best3D = fitter3D.fit(new PolynomialFunction.Parametric(), init3D);
    final PolynomialFunction fitted3D = new PolynomialFunction(best3D);

    // Create plot
    String title = TITLE;
    Plot2 plot = new Plot2(title, "Time (seconds)", "Mean-squared Distance (um^2)", xValues, yValues2D);
    double[] limits = Maths.limits(upper);
    limits = Maths.limits(limits, lower);
    limits = Maths.limits(limits, yValues3D);
    plot.setLimits(0, totalSteps / settings.stepsPerSecond, limits[0], limits[1]);
    plot.setColor(Color.blue);
    plot.addPoints(xValues, lower, Plot2.LINE);
    plot.addPoints(xValues, upper, Plot2.LINE);
    plot.setColor(Color.magenta);
    plot.addPoints(xValues, yValues3D, Plot2.LINE);
    plot.setColor(Color.red);
    plot.addPoints(new double[] { xValues[0], xValues[xValues.length - 1] },
            new double[] { fitted2D.value(xValues[0]), fitted2D.value(xValues[xValues.length - 1]) },
            Plot2.LINE);
    plot.setColor(Color.green);
    plot.addPoints(new double[] { xValues[0], xValues[xValues.length - 1] },
            new double[] { fitted3D.value(xValues[0]), fitted3D.value(xValues[xValues.length - 1]) },
            Plot2.LINE);
    plot.setColor(Color.black);

    Utils.display(title, plot);

    // For 2D diffusion: d^2 = 4D
    // where: d^2 = mean-square displacement

    double D = best2D[1] / 4.0;
    String msg = "2D Diffusion rate = " + Utils.rounded(D, 4) + " um^2 / sec (" + Utils.timeToString(time)
            + ")";
    IJ.showStatus(msg);
    Utils.log(msg);

    D = best3D[1] / 6.0;
    Utils.log("3D Diffusion rate = " + Utils.rounded(D, 4) + " um^2 / sec (" + Utils.timeToString(time) + ")");

    if (useConfinement)
        Utils.log("3D asymptote distance = %s nm (expected %.2f)",
                Utils.rounded(asymptote.getMean() * settings.pixelPitch, 4),
                3 * settings.confinementRadius / 4);
}

From source file:net.sf.jasperreports.engine.util.JRSwapFile.java

/**
 * Creates a swap file.//from w w  w  . j  a  v a 2s .  c o m
 * 
 * The file name is generated automatically.
 * 
 * @param jasperReportsContext the JasperReportsContext to read configuration from.
 * @param directory the directory where the file should be created.
 * @param blockSize the size of the blocks allocated by the swap file
 * @param minGrowCount the minimum number of blocks by which the swap file grows when full
 */
public JRSwapFile(JasperReportsContext jasperReportsContext, String directory, int blockSize,
        int minGrowCount) {
    try {
        String filename = "swap_" + System.identityHashCode(this) + "_" + System.currentTimeMillis();
        swapFile = new File(directory, filename);
        if (log.isDebugEnabled()) {
            log.debug("Creating swap file " + swapFile.getPath());
        }
        boolean fileExists = swapFile.exists();

        boolean deleteOnExit = JRPropertiesUtil.getInstance(jasperReportsContext)
                .getBooleanProperty(PROPERTY_DELETE_ON_EXIT);
        if (deleteOnExit) {
            swapFile.deleteOnExit();
        }

        file = new RandomAccessFile(swapFile, "rw");//FIXME to this lazily?

        this.blockSize = blockSize;
        this.minGrowCount = minGrowCount;
        freeBlocks = new LongQueue(minGrowCount);

        if (fileExists) {
            file.setLength(0);
            if (log.isDebugEnabled()) {
                log.debug("Swap file " + swapFile.getPath() + " exists, truncating");
            }
        }
    } catch (FileNotFoundException e) {
        throw new JRRuntimeException(e);
    } catch (IOException e) {
        throw new JRRuntimeException(e);
    }
}

From source file:org.apache.mnemonic.collections.DurableArrayNGTest.java

@BeforeClass
public void setUp() throws Exception {
    rand = Utils.createRandom();//www  .j  a  v a  2  s . c  o  m
    unsafe = Utils.getUnsafe();
    m_act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
            1024 * 1024 * 1024, "./pobj_array.dat", true);
    cKEYCAPACITY = m_act.handlerCapacity();
    m_act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
        @Override
        public boolean reclaim(ByteBuffer mres, Long sz) {
            System.out.println(String.format("Reclaim Memory Buffer: %X  Size: %s",
                    System.identityHashCode(mres), null == sz ? "NULL" : sz.toString()));
            System.out.println(" String buffer " + mres.asCharBuffer().toString());
            return false;
        }
    });
    m_act.setChunkReclaimer(new Reclaim<Long>() {
        @Override
        public boolean reclaim(Long mres, Long sz) {
            System.out.println(String.format("Reclaim Memory Chunk: %X  Size: %s",
                    System.identityHashCode(mres), null == sz ? "NULL" : sz.toString()));
            return false;
        }
    });

    for (long i = 0; i < cKEYCAPACITY; ++i) {
        m_act.setHandler(i, 0L);
    }
}

From source file:com.arpnetworking.metrics.mad.configuration.PipelineConfiguration.java

/**
 * {@inheritDoc}// www  . j av a 2s.  com
 */
@Override
public String toString() {
    return MoreObjects.toStringHelper(this).add("id", Integer.toHexString(System.identityHashCode(this)))
            .add("Name", _name).add("Sources", _sources).add("Sinks", _sinks).add("Periods", _periods)
            .add("TimerStatistic", _timerStatistic).add("CounterStatistic", _counterStatistic)
            .add("GaugeStatistic", _gaugeStatistic).toString();
}

From source file:net.sf.jasperreports.engine.base.ElementsBlock.java

/**
 * Make a new identifier for an object./*from   w w  w.j a  va  2s.  c o  m*/
 * 
 * @return the new identifier
 */
private String makeUID() {
    //FIXME use UUID?
    return System.identityHashCode(context) + "_" + System.identityHashCode(this) + "_"
            + uidCounter.incrementAndGet() + "_" + uidRandom.nextInt();
}

From source file:org.codehaus.groovy.grails.commons.metaclass.WeakGenericDynamicProperty.java

public void set(Object object, Object newValue) {
    if (!readyOnly) {
        if (this.type.isInstance(newValue))
            propertyToInstanceMap.put(String.valueOf(System.identityHashCode(object)) + getPropertyName(),
                    new SoftReference<Object>(newValue));
        else if (newValue != null)
            throw new MissingPropertyException(
                    "Property '" + this.getPropertyName() + "' for object '" + object.getClass()
                            + "' cannot be set with value '" + newValue + "'. Incorrect type.",
                    object.getClass());/*w  w  w. j a v  a2 s .c om*/
    } else {
        throw new MissingPropertyException("Property '" + this.getPropertyName() + "' for object '"
                + object.getClass() + "' is read-only!", object.getClass());
    }
}