CPD Results

The following document contains the results of PMD's CPD 4.2.2.

Duplications

File Project Line
com\sun\sgs\impl\service\transaction\TransactionImpl0951.java PDS Transactions API 111
com\sun\sgs\impl\service\transaction\TransactionImpl096.java PDS Transactions API 111
    public TransactionImpl096(long tid, long timeout, ProfileCollector collector) {
    this.tid = tid;
    this.timeout = timeout;
    this.collector = collector;
    creationTime = System.currentTimeMillis();
    owner = Thread.currentThread();
    state = State.ACTIVE;
    if (collector != null) {
        detailMap = new HashMap<String,ProfileParticipantDetailImpl>();
    } else {
        detailMap = null;
    }
    logger.log(Level.FINER, "create {0}", this);
    }

    /* -- Implement Transaction -- */

    /** {@inheritDoc} */
    public byte[] getId() {
    return longToBytes(tid);
    }

    /** {@inheritDoc} */
    public long getCreationTime() {
    return creationTime;
    }

    /** {@inheritDoc} */
    public long getTimeout() {
    return timeout;
    }

    /** {@inheritDoc} */
    public void checkTimeout() {
    assert Thread.currentThread() == owner : "Wrong thread";
    logger.log(Level.FINEST, "checkTimeout {0}", this);
    switch (state) {
    case ABORTED:
    case COMMITTED:
        throw new TransactionNotActiveException(
        "Transaction is not active: " + state);
    case ABORTING:
    case COMMITTING:
        return;
    case ACTIVE:
    case PREPARING:
        break;
    default:
        throw new AssertionError();
    }
    long runningTime = System.currentTimeMillis() - getCreationTime();
    if (runningTime > getTimeout()) {
        TransactionTimeoutException exception =
        new TransactionTimeoutException(
            "transaction timed out: " + runningTime + " ms");
        abort(exception);
        throw exception;
    }
    }

    /** {@inheritDoc} */
    public void join(TransactionParticipant participant) {
    assert Thread.currentThread() == owner : "Wrong thread";
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "join {0} participant:{1}", this,
               participant);
    }
    if (participant == null) {
        throw new NullPointerException("Participant must not be null");
    } else if (state == State.ABORTED) {
        throw new MaybeRetryableTransactionNotActiveException(
        "Transaction is not active", abortCause);
    } else if (state != State.ACTIVE) {
        throw new IllegalStateException(
        "Transaction is not active: " + state);
    }
    if (!participants.contains(participant)) {
        if (participant instanceof NonDurableTransactionParticipant) {
        if (hasDurableParticipant) {
            participants.add(participants.size() - 1, participant);
        } else {
            participants.add(participant);
        }
        } else if (!hasDurableParticipant) {
        hasDurableParticipant = true;
        participants.add(participant);
        } else {
        throw new UnsupportedOperationException(
            "Attempt to add multiple durable participants");
        }
        if (collector != null) {
        String name = participant.getTypeName();

File Project Line
com\sun\sgs\impl\service\transaction\TransactionImpl0951.java PDS Transactions API 349
com\sun\sgs\impl\service\transaction\TransactionImpl096.java PDS Transactions API 351
        detail = detailMap.get(participant.getTypeName());
        startTime = System.currentTimeMillis();
        }
        try {
        if (iter.hasNext()) {
            boolean readOnly = participant.prepare(this);
            if (collector != null) {
            detail.setPrepared(System.currentTimeMillis() -
                       startTime, readOnly);
            }
            if (readOnly) {
            iter.remove();
            if (collector != null)
                collector.addParticipant(detail);
            }
            if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST,
                   "prepare {0} participant:{1} returns {2}",
                   this, participant, readOnly);
            }
        } else {
            participant.prepareAndCommit(this);
            if (collector != null) {
            detail.
                setCommittedDirectly(System.currentTimeMillis() -
                         startTime);
            collector.addParticipant(detail);
            }
            iter.remove();
            if (logger.isLoggable(Level.FINEST)) {
            logger.log(
                Level.FINEST,
                "prepareAndCommit {0} participant:{1} returns",
                this, participant);
            }
        }
        } catch (Exception e) {
        if (logger.isLoggable(Level.FINEST)) {
            logger.logThrow(
            Level.FINEST, e, "{0} {1} participant:{1} throws",
            iter.hasNext() ? "prepare" : "prepareAndCommit",
            this, participant);
        }
        if (state != State.ABORTED) {
            abort(e);
        }
        throw e;
        }
        if (state == State.ABORTED) {
        throw new MaybeRetryableTransactionAbortedException(
            "Transaction has been aborted", abortCause);
        }
    }
    state = State.COMMITTING;
    for (TransactionParticipant participant : participants) {
        if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "commit {0} participant:{1}",
               this, participant);
        }
        if (collector != null) {
        detail = detailMap.get(participant.getTypeName());

File Project Line
com\sun\sgs\impl\service\transaction\TransactionImpl0951.java PDS Transactions API 293
com\sun\sgs\impl\service\transaction\TransactionImpl096.java PDS Transactions API 295
            return tid == ((TransactionImpl096) object).tid;
        }
        if (object instanceof Transaction)
        {
            final byte[] thisTid = this.getId();
            final byte[] otherTid = ((Transaction) object).getId();
            return Arrays.equals(thisTid, otherTid);
        }
        return false;
    }

    /**
     * Returns a hash code value for this object.
     *
     * @return  a hash code value for this object.
     */
    public int hashCode() {
    return (int) (tid >>> 32) ^ (int) tid;
    }

    /* -- Other methods -- */

    /**
     * Commits this transaction
     *
     * @throws  TransactionNotActiveException if the transaction has been
     *      aborted
     * @throws  TransactionAbortedException if a call to {@link
     *      TransactionParticipant#prepare prepare} on a transaction
     *      participant aborts the transaction but does not throw an
     *      exception
     * @throws  IllegalStateException if {@code prepare} has been called on any
     *      transaction participant and {@link Transaction#abort abort} has
     *      not been called on the transaction
     * @throws  Exception any exception thrown when calling {@code prepare} on
     *      a participant
     * @see TransactionHandle#commit TransactionHandle.commit
     */
    public void commit() throws Exception {
    assert Thread.currentThread() == owner : "Wrong thread";
    logger.log(Level.FINER, "commit {0}", this);
    if (state == State.ABORTED) {
        throw new MaybeRetryableTransactionNotActiveException(
        "Transaction is not active", abortCause);
    } else if (state != State.ACTIVE) {
        throw new IllegalStateException(
        "Transaction is not active: " + state);
    }
    state = State.PREPARING;
    long startTime = 0;
    ProfileParticipantDetailImpl detail = null;
    for (Iterator<TransactionParticipant> iter = participants.iterator();
         iter.hasNext(); )
    {
        TransactionParticipant participant = iter.next();
        if (collector != null) {
        detail = detailMap.get(participant.getTypeName());

File Project Line
com\sun\sgs\impl\service\transaction\TransactionImpl0951.java PDS Transactions API 409
com\sun\sgs\impl\service\transaction\TransactionImpl096.java PDS Transactions API 411
        detail = detailMap.get(participant.getTypeName());
        startTime = System.currentTimeMillis();
        }
        try {
        participant.commit(this);
        if (collector != null) {
            detail.setCommitted(System.currentTimeMillis() -
                    startTime);
            collector.addParticipant(detail);
        }
        } catch (RuntimeException e) {
        if (logger.isLoggable(Level.WARNING)) {
            logger.logThrow(
            Level.WARNING, e, "commit {0} participant:{1} failed",
            this, participant);
        }
        }
    }
    state = State.COMMITTED;
    }

    /** Returns a byte array that represents the specified long. */
    private byte[] longToBytes(long l) {
    return new byte[] {
        (byte) (l >>> 56), (byte) (l >>> 48), (byte) (l >>> 40),
        (byte) (l >>> 32), (byte) (l >>> 24), (byte) (l >>> 16),
        (byte) (l >>> 8), (byte) l };
    }
}

File Project Line
com\pentagaia\tb\start\kernel0951\PropertyParser_0_9_5_1.java PDS 0.9.5.1 implementation 46
com\pentagaia\tb\start\kernel096\PropertyParser_0_9_6.java PDS 0.9.6 implementation 46
public class PropertyParser_0_9_6 implements IPdsPropertyParser
{

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsPropertyParser#refactor(java.util.Properties, java.util.Properties)
     */
    public void refactor(final Properties systemProperties, final Properties applicationProperties)
    {
        // taken from Kernel.Main
        if (systemProperties.containsKey(StandardProperties.APP_NAME))
        {
            throw new IllegalArgumentException("Application name was specified in system properties"); //$NON-NLS-1$
        }

        // make sure that at least the required keys are present, and if
        // they are then start the application
        if (applicationProperties.getProperty(StandardProperties.APP_NAME) == null)
        {
            throw new IllegalStateException("Missing required property " + StandardProperties.APP_NAME + " from application config."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (applicationProperties.getProperty(StandardProperties.APP_ROOT) == null)
        {
            throw new IllegalStateException("Missing required property " + StandardProperties.APP_ROOT + " from application config."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (applicationProperties.getProperty(StandardProperties.APP_LISTENER) == null)
        {
            throw new IllegalStateException("Missing required property " + StandardProperties.APP_LISTENER + " from application config."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (applicationProperties.getProperty(StandardProperties.APP_PORT) == null)
        {
            throw new IllegalStateException("Missing required property " + StandardProperties.APP_PORT + " from application config."); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

}

File Project Line
com\sun\sgs\impl\service\transaction\TransactionImpl0951.java PDS Transactions API 224
com\sun\sgs\impl\service\transaction\TransactionImpl096.java PDS Transactions API 226
        "Transaction is not active: " + state, cause);
    default:
        throw new AssertionError();
    }
    state = State.ABORTING;
    abortCause = cause;
    long startTime = 0;
    for (TransactionParticipant participant : participants) {
        if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "abort {0} participant:{1}",
               this, participant);
        }
        if (collector != null) {
        startTime = System.currentTimeMillis();
        }
        try {
        participant.abort(this);
        } catch (RuntimeException e) {
        if (logger.isLoggable(Level.WARNING)) {
            logger.logThrow(
            Level.WARNING, e, "abort {0} participant:{1} failed",
            this, participant);
        }
        }
        if (collector != null) {
        long finishTime = System.currentTimeMillis();
        ProfileParticipantDetailImpl detail =
            detailMap.get(participant.getTypeName());

File Project Line
com\pentagaia\tb\start\kernel0951\ClassLoaderExtension_0_9_5_1.java PDS 0.9.5.1 implementation 96
com\pentagaia\tb\start\kernel096\ClassLoaderExtension_0_9_6.java PDS 0.9.6 implementation 96
            throw new IllegalStateException("Unable to load KernelContext.0.9.6.class.bin"); //$NON-NLS-1$
        }
        
        // we do not replace unknown classes
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#loadClassExternal(java.lang.String)
     */
    public Class<?> loadClassExternal(@SuppressWarnings("unused")
    final String className)
    {
        // we do not load the classes in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#refactorClass(java.lang.String, byte[])
     */
    public byte[] refactorClass(@SuppressWarnings("unused")
    final String className, @SuppressWarnings("unused")
    final byte[] source)
    {
        // we do not manipulate byte code in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#getResource(java.lang.String)
     */
    public URL getResource(@SuppressWarnings("unused")
    String name)
    {
        // we do not manipulate resources in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#getResourceFirst(java.lang.String)
     */
    public URL getResourceFirst(@SuppressWarnings("unused")
    String name)
    {
        // we do not manipulate resources in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#getResources(java.lang.String)
     */
    public Enumeration<URL> getResources(@SuppressWarnings("unused")
    String name)
    {
        // we do not manipulate resources in this extension
        return null;
    }

}

File Project Line
com\pentagaia\tb\start\kernel0951\ClassLoaderExtension_0_9_5_1.java PDS 0.9.5.1 implementation 100
com\pentagaia\tb\start\impl\ClassLoaderExtension.java Startup API 112
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#loadClassExternal(java.lang.String)
     */
    public Class<?> loadClassExternal(@SuppressWarnings("unused")
    final String className)
    {
        // we do not load the classes in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#refactorClass(java.lang.String, byte[])
     */
    public byte[] refactorClass(@SuppressWarnings("unused")
    final String className, @SuppressWarnings("unused")
    final byte[] source)
    {
        // we do not manipulate byte code in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#getResource(java.lang.String)
     */
    public URL getResource(@SuppressWarnings("unused")
    String name)
    {
        // we do not manipulate resources in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#getResourceFirst(java.lang.String)
     */
    public URL getResourceFirst(@SuppressWarnings("unused")
    String name)
    {
        // we do not manipulate resources in this extension
        return null;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.pentagaia.tb.start.IPdsClassLoaderExtension#getResources(java.lang.String)
     */
    public Enumeration<URL> getResources(@SuppressWarnings("unused")
    String name)
    {
        // we do not manipulate resources in this extension
        return null;
    }

}