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.ailis.midi4js.Midi4JS.java

/**
 * Returns MIDI IN receiver for the specified device. A receiver must
 * be closed when no longer needed.//from w w w  . j  a va  2  s.  co m
 *
 * @param deviceHandle
 *            The handle of the MIDI device.
 * @return The handle of the receiver.
 * @throws MidiUnavailableException
 *             When MIDI device is unavailable.
 */
public int getReceiver(final int deviceHandle) throws MidiUnavailableException {
    final MidiDevice device = resolveDeviceHandle(deviceHandle);
    final Receiver receiver = device.getReceiver();
    final int receiverHandle = System.identityHashCode(receiver);
    this.receiverMap.put(receiverHandle, receiver);
    return receiverHandle;
}

From source file:org.polymap.core.runtime.event.EventManager.java

/**
 *
 * @param listenerOrHandler//from   w w  w.ja v a 2 s. c o m
 * @throws True if the given handler actually was removed.
 */
public boolean unsubscribe(Object annotated) {
    assert annotated != null;
    Integer key = System.identityHashCode(annotated);
    return removeKey(key) != null;
}

From source file:org.helios.jzab.agent.net.active.ActiveClient.java

/**
 * Creates a new ActiveClient/*from w  w w .  j av  a2s .  c  om*/
 * @param configNode The configuration node
 */
private ActiveClient(Node configNode) {
    super(ThreadPoolFactory.getInstance("NotificationProcessor"));
    if (configNode == null)
        throw new IllegalArgumentException("The passed configuration node was null", new Throwable());
    String nodeName = configNode.getNodeName();
    if (!NODE.equals(nodeName)) {
        throw new RuntimeException(
                "Configuration Node expected to have node name [" + NODE + "] but was [" + nodeName + "]",
                new Throwable());
    }
    agentName = XMLHelper.getAttributeByName(configNode, "name",
            "ActiveClient@" + System.identityHashCode(this));
    loggingHandler = new ZabbixLoggingHandler(agentName, InternalLogLevel.DEBUG, true);
    objectName = JMXHelper.objectName("org.helios.jzab.agent.net", "service", "ActiveClient", "name",
            agentName);
    bossPool = ThreadPoolFactory.getInstance(XMLHelper
            .getAttributeByName(XMLHelper.getChildNodeByName(configNode, BOSS_POOL_TYPE, false), "name", null));
    workerPool = ThreadPoolFactory.getInstance(XMLHelper.getAttributeByName(
            XMLHelper.getChildNodeByName(configNode, WORKER_POOL_TYPE, false), "name", null));
    Node socketOpts = XMLHelper.getChildNodeByName(configNode, "socket-options", false);
    if (socketOpts != null) {
        for (Node socketOption : XMLHelper.getChildNodesByName(socketOpts, "opt", false)) {
            String valueStr = XMLHelper.getAttributeByName(socketOption, "value", "-1").trim().toLowerCase();
            Object value = null;
            if (valueStr.equalsIgnoreCase("true") || valueStr.equalsIgnoreCase("false")) {
                value = valueStr.equalsIgnoreCase("true");
            } else {
                try {
                    value = Integer.parseInt(valueStr);
                } catch (Exception e) {
                    value = valueStr;
                }
            }
            socketOptions.put(XMLHelper.getAttributeByName(socketOption, "name", null), value);
        }
    }
    channelGroup = new DefaultChannelGroup(agentName + "-ChannelGroup");
    channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);

    bstrap = new ClientBootstrap(channelFactory);
    bstrap.setPipelineFactory(this);
    bstrap.setOptions(socketOptions);
    JMXHelper.registerMBean(JMXHelper.getHeliosMBeanServer(), OBJECT_NAME, this);
    log.info("Created ActiveAgent [{}]", agentName);
}

From source file:IdentityHashMap.java

/**
 * Returns the value to which this map maps the specified key.  Returns
 * <tt>null</tt> if the map contains no mapping for this key.  A return
 * value of <tt>null</tt> does not <i>necessarily</i> indicate that the
 * map contains no mapping for the key; it's also possible that the map
 * explicitly maps the key to <tt>null</tt>.  The <tt>containsKey</tt>
 * operation may be used to distinguish these two cases.
 *
 * @return the value to which this map maps the specified key.
 * @param key key whose associated value is to be returned.
 *///  w w  w  .  ja v  a2  s .c o  m
public Object get(Object key) {
    Entry tab[] = table;

    if (key != null) {
        // int hash = key.hashCode();
        int hash = System.identityHashCode(key);
        int index = (hash & 0x7FFFFFFF) % tab.length;
        for (Entry e = tab[index]; e != null; e = e.next)
            // if ((e.hash == hash) && key.equals(e.key))
            if ((e.hash == hash) && (key == e.key))
                return e.value;
    } else {
        for (Entry e = tab[0]; e != null; e = e.next)
            if (e.key == null)
                return e.value;
    }

    return null;
}

From source file:com.sworddance.util.perf.LapTimer.java

/**
 * Creates a new instance of LapTimer//from   ww  w.  j  a v a 2s.  c  o  m
 *
 * @param actual
 */
public LapTimer(Runnable actual) {
    this(null, actual, 100);
    this.timerName = "LapTimer#" + System.identityHashCode(this);
}

From source file:brooklyn.util.internal.ssh.sshj.SshjTool.java

@Override
public void disconnect() {
    if (LOG.isTraceEnabled())
        LOG.trace("Disconnecting SshjTool {} ({})", this, System.identityHashCode(this));
    try {/*  ww  w .  j a  va 2  s. c o m*/
        Stopwatch perfStopwatch = Stopwatch.createStarted();
        sshClientConnection.clear();
        if (LOG.isTraceEnabled())
            LOG.trace("SSH Performance: {} disconnect took {}", sshClientConnection.getHostAndPort(),
                    Time.makeTimeStringRounded(perfStopwatch));
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
}

From source file:org.red5.server.stream.ClientBroadcastStream.java

/**
 * Dispatches event//w ww  . ja v  a  2 s .  c o m
 * 
 * @param event
 *            Event to dispatch
 */
public void dispatchEvent(IEvent event) {
    if (event instanceof IRTMPEvent && !closed) {
        switch (event.getType()) {
        case STREAM_CONTROL:
        case STREAM_DATA:
            // create the event
            IRTMPEvent rtmpEvent;
            try {
                rtmpEvent = (IRTMPEvent) event;
            } catch (ClassCastException e) {
                log.error("Class cast exception in event dispatch", e);
                return;
            }
            int eventTime = -1;
            if (log.isTraceEnabled()) {
                // If this is first packet save its timestamp; expect it is
                // absolute? no matter: it's never used!
                if (firstPacketTime == -1) {
                    firstPacketTime = rtmpEvent.getTimestamp();
                    log.trace(String.format("CBS=@%08x: rtmpEvent=%s creation=%s firstPacketTime=%d",
                            System.identityHashCode(this), rtmpEvent.getClass().getSimpleName(), creationTime,
                            firstPacketTime));
                } else {
                    log.trace(
                            String.format("CBS=@%08x: rtmpEvent=%s creation=%s firstPacketTime=%d timestamp=%d",
                                    System.identityHashCode(this), rtmpEvent.getClass().getSimpleName(),
                                    creationTime, firstPacketTime, rtmpEvent.getTimestamp()));
                }
            }
            //get the buffer only once per call
            IoBuffer buf = null;
            if (rtmpEvent instanceof IStreamData && (buf = ((IStreamData<?>) rtmpEvent).getData()) != null) {
                bytesReceived += buf.limit();
            }
            // get stream codec
            IStreamCodecInfo codecInfo = getCodecInfo();
            StreamCodecInfo info = null;
            if (codecInfo instanceof StreamCodecInfo) {
                info = (StreamCodecInfo) codecInfo;
            }
            //log.trace("Stream codec info: {}", info);
            if (rtmpEvent instanceof AudioData) {
                IAudioStreamCodec audioStreamCodec = null;
                if (checkAudioCodec) {
                    // dont try to read codec info from 0 length audio packets
                    if (buf.limit() > 0) {
                        audioStreamCodec = AudioCodecFactory.getAudioCodec(buf);
                        if (info != null) {
                            info.setAudioCodec(audioStreamCodec);
                        }
                        checkAudioCodec = false;
                    }
                } else if (codecInfo != null) {
                    audioStreamCodec = codecInfo.getAudioCodec();
                }
                if (audioStreamCodec != null) {
                    audioStreamCodec.addData(buf);
                }
                if (info != null) {
                    info.setHasAudio(true);
                }
                eventTime = rtmpEvent.getTimestamp();
                log.trace("Audio: {}", eventTime);
            } else if (rtmpEvent instanceof VideoData) {
                IVideoStreamCodec videoStreamCodec = null;
                if (checkVideoCodec) {
                    videoStreamCodec = VideoCodecFactory.getVideoCodec(buf);
                    if (info != null) {
                        info.setVideoCodec(videoStreamCodec);
                    }
                    checkVideoCodec = false;
                } else if (codecInfo != null) {
                    videoStreamCodec = codecInfo.getVideoCodec();
                }
                if (videoStreamCodec != null) {
                    videoStreamCodec.addData(buf);
                }
                if (info != null) {
                    info.setHasVideo(true);
                }
                eventTime = rtmpEvent.getTimestamp();
                log.trace("Video: {}", eventTime);
            } else if (rtmpEvent instanceof Invoke) {
                Invoke invokeEvent = (Invoke) rtmpEvent;
                log.debug("Invoke action: {}", invokeEvent.getAction());
                eventTime = rtmpEvent.getTimestamp();
                // event / stream listeners will not be notified of invokes
                return;
            } else if (rtmpEvent instanceof Notify) {
                Notify notifyEvent = (Notify) rtmpEvent;
                log.debug("Notify action: {}", notifyEvent.getAction());
                if (notifyEvent.getAction() != null && notifyEvent.getAction().equals("onMetaData")) {
                    // store the metadata
                    try {
                        log.debug("Setting metadata");
                        metaData = notifyEvent.duplicate();
                    } catch (Exception e) {
                        log.warn("Metadata could not be duplicated for this stream", e);
                    }
                }
                eventTime = rtmpEvent.getTimestamp();
            }
            // update last event time
            if (eventTime > latestTimeStamp) {
                latestTimeStamp = eventTime;
            }
            // notify event listeners
            checkSendNotifications(event);
            // note this timestamp is set in event/body but not in the associated header
            try {
                // route to live
                if (livePipe != null) {
                    // create new RTMP message, initialize it and push through pipe
                    RTMPMessage msg = RTMPMessage.build(rtmpEvent, eventTime);
                    livePipe.pushMessage(msg);
                } else {
                    log.debug("Live pipe was null, message was not pushed");
                }
            } catch (IOException err) {
                stop();
            }
            // notify listeners about received packet
            if (rtmpEvent instanceof IStreamPacket) {
                for (IStreamListener listener : getStreamListeners()) {
                    try {
                        listener.packetReceived(this, (IStreamPacket) rtmpEvent);
                    } catch (Exception e) {
                        log.error("Error while notifying listener {}", listener, e);
                        if (listener instanceof RecordingListener) {
                            sendRecordFailedNotify(e.getMessage());
                        }
                    }
                }
            }
            break;
        default:
            // ignored event
            log.debug("Ignoring event: {}", event.getType());
        }
    } else {
        log.debug("Event was of wrong type or stream is closed ({})", closed);
    }
}

From source file:com.sworddance.util.perf.LapTimer.java

/**
 * @param actual/*  www  .  j  a  va2 s  .c o  m*/
 * @param lapHistorySize
 */
public LapTimer(Runnable actual, int lapHistorySize) {
    this(null, actual, lapHistorySize);
    this.timerName = "LapTimer#" + System.identityHashCode(this);
}

From source file:org.apache.hadoop.hive.llap.cache.LlapAllocatorBuffer.java

@Override
public String toString() {
    long state = this.state.get();
    int flags = State.getAllFlags(state);
    return "0x" + Integer.toHexString(System.identityHashCode(this)) + "(" + State.getRefCount(state)
            + (flags == 0 ? "" : (", " + State.toFlagString(flags))) + ")";
}

From source file:com.cloud.utils.db.Transaction.java

public static Connection getStandaloneSimulatorConnection() {
    try {// ww  w . j a v a  2 s . c o m
        Connection conn = s_simulatorDS.getConnection();
        if (s_connLogger.isTraceEnabled()) {
            s_connLogger.trace(
                    "Retrieving a standalone connection for simulator: dbconn" + System.identityHashCode(conn));
        }
        return conn;
    } catch (SQLException e) {
        s_logger.warn("Unexpected exception: ", e);
        return null;
    }
}