Java Code Examples for org.agrona.collections.ArrayUtil#add()

The following examples show how to use org.agrona.collections.ArrayUtil#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicCompositeAgent.java    From agrona with Apache License 2.0 6 votes vote down vote up
private void add(final Agent agent)
{
    addAgent.lazySet(null);

    try
    {
        agent.onStart();
    }
    catch (final RuntimeException ex)
    {
        agent.onClose();
        throw ex;
    }

    agents = ArrayUtil.add(agents, agent);
}
 
Example 2
Source File: LibraryPoller.java    From artio with Apache License 2.0 6 votes vote down vote up
private int pollPendingInitiatorSessions(final long timeInMs)
{
    InternalSession[] pendingSessions = this.pendingInitiatorSessions;
    int total = 0;

    for (int i = 0, size = pendingSessions.length; i < size;)
    {
        final InternalSession session = pendingSessions[i];
        total += session.poll(timeInMs);
        if (session.state() == ACTIVE)
        {
            this.pendingInitiatorSessions = pendingSessions = ArrayUtil.remove(pendingSessions, i);
            size--;
            sessions = ArrayUtil.add(sessions, session);
        }
        else
        {
            i++;
        }
    }

    return total;
}
 
Example 3
Source File: NetworkPublication.java    From aeron with Apache License 2.0 6 votes vote down vote up
public void addSubscriber(final SubscriptionLink subscriptionLink, final ReadablePosition position)
{
    spyPositions = ArrayUtil.add(spyPositions, position);
    hasSpies = true;

    if (!subscriptionLink.isTether())
    {
        untetheredSubscriptions.add(new UntetheredSubscription(subscriptionLink, position, nanoClock.nanoTime()));
    }

    if (spiesSimulateConnection)
    {
        LogBufferDescriptor.isConnected(metaDataBuffer, true);
        isConnected = true;
    }
}
 
Example 4
Source File: DataTransportPoller.java    From aeron with Apache License 2.0 6 votes vote down vote up
public SelectionKey registerForRead(
    final ReceiveChannelEndpoint channelEndpoint, final UdpChannelTransport transport, final int transportIndex)
{
    SelectionKey key = null;
    try
    {
        final ChannelAndTransport channelAndTransport = new ChannelAndTransport(
            channelEndpoint, transport, transportIndex);

        key = transport.receiveDatagramChannel().register(selector, SelectionKey.OP_READ, channelAndTransport);
        channelAndTransports = ArrayUtil.add(channelAndTransports, channelAndTransport);
    }
    catch (final ClosedChannelException ex)
    {
        LangUtil.rethrowUnchecked(ex);
    }

    return key;
}
 
Example 5
Source File: IpcPublication.java    From aeron with Apache License 2.0 5 votes vote down vote up
public void addSubscriber(final SubscriptionLink subscriptionLink, final ReadablePosition subscriberPosition)
{
    subscriberPositions = ArrayUtil.add(subscriberPositions, subscriberPosition);
    if (!subscriptionLink.isTether())
    {
        untetheredSubscriptions.add(new UntetheredSubscription(
            subscriptionLink, subscriberPosition, timeOfLastConsumerPositionUpdateNs));
    }

    LogBufferDescriptor.isConnected(metaDataBuffer, true);
}
 
Example 6
Source File: ControlTransportPoller.java    From aeron with Apache License 2.0 5 votes vote down vote up
public SelectionKey registerForRead(final SendChannelEndpoint transport)
{
    SelectionKey key = null;
    try
    {
        key = transport.receiveDatagramChannel().register(selector, SelectionKey.OP_READ, transport);
        transports = ArrayUtil.add(transports, transport);
    }
    catch (final ClosedChannelException ex)
    {
        LangUtil.rethrowUnchecked(ex);
    }

    return key;
}
 
Example 7
Source File: PublicationImage.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void addSubscriber(final SubscriptionLink subscriptionLink, final ReadablePosition subscriberPosition)
{
    subscriberPositions = ArrayUtil.add(subscriberPositions, subscriberPosition);
    if (!subscriptionLink.isTether())
    {
        untetheredSubscriptions.add(new UntetheredSubscription(
            subscriptionLink, subscriberPosition, timeOfLastStatusMessageScheduleNs));
    }
}
 
Example 8
Source File: ReceiverEndPoints.java    From artio with Apache License 2.0 5 votes vote down vote up
void add(final ReceiverEndPoint endPoint)
{
    if (endPoint.requiresAuthentication())
    {
        requiredPollingEndPoints = ArrayUtil.add(requiredPollingEndPoints, endPoint);
    }
    else
    {
        addToNormalEndpoints(endPoint);
    }
}
 
Example 9
Source File: LibraryPoller.java    From artio with Apache License 2.0 5 votes vote down vote up
public Action onILinkConnect(
    final int libraryId,
    final long correlationId,
    final long connectionId,
    final long uuid,
    final long lastReceivedSequenceNumber,
    final long lastSentSequenceNumber,
    final boolean newlyAllocated)
{
    if (libraryId == this.libraryId)
    {
        final InitiateILink3ConnectionReply reply =
            (InitiateILink3ConnectionReply)correlationIdToReply.remove(correlationId);

        if (reply != null)
        {
            DebugLogger.log(FIX_CONNECTION, initiatorConnectFormatter, connectionId, libraryId);

            reply.onTcpConnected();

            final ILink3ConnectionConfiguration configuration = reply.configuration();
            final ILink3Connection connection = makeILink3Connection(
                configuration, connectionId, reply, libraryId, this,
                uuid, lastReceivedSequenceNumber, lastSentSequenceNumber, newlyAllocated);
            final ILink3Subscription subscription = new ILink3Subscription(
                AbstractILink3Parser.make(connection, THROW_ERRORS), connection);
            connectionIdToILink3Subscription.put(connectionId, subscription);
            iLink3Connections = ArrayUtil.add(iLink3Connections, connection);
        }
    }

    return CONTINUE;
}
 
Example 10
Source File: LibraryPoller.java    From artio with Apache License 2.0 5 votes vote down vote up
private void insertSession(
    final InternalSession session, final ConnectionType connectionType, final SessionState sessionState)
{
    if (connectionType == INITIATOR && sessionState != ACTIVE)
    {
        pendingInitiatorSessions = ArrayUtil.add(pendingInitiatorSessions, session);
    }
    else
    {
        sessions = ArrayUtil.add(sessions, session);
    }
}
 
Example 11
Source File: ReceiverEndPoints.java    From artio with Apache License 2.0 5 votes vote down vote up
private void addToNormalEndpoints(final ReceiverEndPoint endPoint)
{
    try
    {
        endPoints = ArrayUtil.add(endPoints, endPoint);
        endPoint.register(selector);
    }
    catch (final IOException ex)
    {
        LangUtil.rethrowUnchecked(ex);
    }
}
 
Example 12
Source File: Sender.java    From aeron with Apache License 2.0 4 votes vote down vote up
public void onNewNetworkPublication(final NetworkPublication publication)
{
    networkPublications = ArrayUtil.add(networkPublications, publication);
    publication.channelEndpoint().registerForSend(publication);
}
 
Example 13
Source File: IpcPublication.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void checkUntetheredSubscriptions(final long nowNs, final DriverConductor conductor)
{
    final long untetheredWindowLimit = (consumerPosition - termWindowLength) + (termWindowLength >> 3);

    for (int lastIndex = untetheredSubscriptions.size() - 1, i = lastIndex; i >= 0; i--)
    {
        final UntetheredSubscription untethered = untetheredSubscriptions.get(i);
        if (UntetheredSubscription.State.ACTIVE == untethered.state)
        {
            if (untethered.position.getVolatile() > untetheredWindowLimit)
            {
                untethered.timeOfLastUpdateNs = nowNs;
            }
            else if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0)
            {
                conductor.notifyUnavailableImageLink(registrationId, untethered.subscriptionLink);
                untethered.state(UntetheredSubscription.State.LINGER, nowNs, streamId, sessionId);
            }
        }
        else if (UntetheredSubscription.State.LINGER == untethered.state)
        {
            if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0)
            {
                subscriberPositions = ArrayUtil.remove(subscriberPositions, untethered.position);
                untethered.state(UntetheredSubscription.State.RESTING, nowNs, streamId, sessionId);
            }
        }
        else if (UntetheredSubscription.State.RESTING == untethered.state)
        {
            if ((untethered.timeOfLastUpdateNs + untetheredRestingTimeoutNs) - nowNs <= 0)
            {
                subscriberPositions = ArrayUtil.add(subscriberPositions, untethered.position);
                conductor.notifyAvailableImageLink(
                    registrationId,
                    sessionId,
                    untethered.subscriptionLink,
                    untethered.position.id(),
                    consumerPosition,
                    rawLog.fileName(),
                    CommonContext.IPC_CHANNEL);
                untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId);
                LogBufferDescriptor.isConnected(metaDataBuffer, true);
            }
        }
    }
}
 
Example 14
Source File: Subscription.java    From aeron with Apache License 2.0 4 votes vote down vote up
void addImage(final Image image)
{
    images = ArrayUtil.add(images, image);
}
 
Example 15
Source File: PublicationImage.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void checkUntetheredSubscriptions(final long nowNs, final DriverConductor conductor)
{
    final ArrayList<UntetheredSubscription> untetheredSubscriptions = this.untetheredSubscriptions;
    final int untetheredSubscriptionsSize = untetheredSubscriptions.size();
    if (untetheredSubscriptionsSize > 0)
    {
        long maxConsumerPosition = 0;
        for (final ReadablePosition subscriberPosition : subscriberPositions)
        {
            final long position = subscriberPosition.getVolatile();
            if (position > maxConsumerPosition)
            {
                maxConsumerPosition = position;
            }
        }

        final int windowLength = nextSmReceiverWindowLength;
        final long untetheredWindowLimit = (maxConsumerPosition - windowLength) + (windowLength >> 3);

        for (int lastIndex = untetheredSubscriptionsSize - 1, i = lastIndex; i >= 0; i--)
        {
            final UntetheredSubscription untethered = untetheredSubscriptions.get(i);
            if (UntetheredSubscription.State.ACTIVE == untethered.state)
            {
                if (untethered.position.getVolatile() > untetheredWindowLimit)
                {
                    untethered.timeOfLastUpdateNs = nowNs;
                }
                else if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0)
                {
                    conductor.notifyUnavailableImageLink(correlationId, untethered.subscriptionLink);
                    untethered.state(UntetheredSubscription.State.LINGER, nowNs, streamId, sessionId);
                }
            }
            else if (UntetheredSubscription.State.LINGER == untethered.state)
            {
                if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0)
                {
                    subscriberPositions = ArrayUtil.remove(subscriberPositions, untethered.position);
                    untethered.state(UntetheredSubscription.State.RESTING, nowNs, streamId, sessionId);
                }
            }
            else if (UntetheredSubscription.State.RESTING == untethered.state)
            {
                if ((untethered.timeOfLastUpdateNs + untetheredRestingTimeoutNs) - nowNs <= 0)
                {
                    subscriberPositions = ArrayUtil.add(subscriberPositions, untethered.position);
                    conductor.notifyAvailableImageLink(
                        correlationId,
                        sessionId,
                        untethered.subscriptionLink,
                        untethered.position.id(),
                        rebuildPosition.get(),
                        rawLog.fileName(),
                        Configuration.sourceIdentity(sourceAddress));
                    untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId);
                }
            }
        }
    }
}
 
Example 16
Source File: NetworkPublication.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void checkUntetheredSubscriptions(final long nowNs, final DriverConductor conductor)
{
    final ArrayList<UntetheredSubscription> untetheredSubscriptions = this.untetheredSubscriptions;
    final int untetheredSubscriptionsSize = untetheredSubscriptions.size();
    if (untetheredSubscriptionsSize > 0)
    {
        final long senderPosition = this.senderPosition.getVolatile();
        final long untetheredWindowLimit = (senderPosition - termWindowLength) + (termWindowLength >> 3);

        for (int lastIndex = untetheredSubscriptionsSize - 1, i = lastIndex; i >= 0; i--)
        {
            final UntetheredSubscription untethered = untetheredSubscriptions.get(i);
            if (UntetheredSubscription.State.ACTIVE == untethered.state)
            {
                if (untethered.position.getVolatile() > untetheredWindowLimit)
                {
                    untethered.timeOfLastUpdateNs = nowNs;
                }
                else if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0)
                {
                    conductor.notifyUnavailableImageLink(registrationId, untethered.subscriptionLink);
                    untethered.state(UntetheredSubscription.State.LINGER, nowNs, streamId, sessionId);
                }
            }
            else if (UntetheredSubscription.State.LINGER == untethered.state)
            {
                if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0)
                {
                    spyPositions = ArrayUtil.remove(spyPositions, untethered.position);
                    untethered.state(UntetheredSubscription.State.RESTING, nowNs, streamId, sessionId);
                }
            }
            else if (UntetheredSubscription.State.RESTING == untethered.state)
            {
                if ((untethered.timeOfLastUpdateNs + untetheredRestingTimeoutNs) - nowNs <= 0)
                {
                    spyPositions = ArrayUtil.add(spyPositions, untethered.position);
                    conductor.notifyAvailableImageLink(
                        registrationId,
                        sessionId,
                        untethered.subscriptionLink,
                        untethered.position.id(),
                        senderPosition,
                        rawLog.fileName(),
                        CommonContext.IPC_CHANNEL);
                    untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId);
                    LogBufferDescriptor.isConnected(metaDataBuffer, true);
                }
            }
        }
    }
}
 
Example 17
Source File: ClusterMember.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Add a new member to an array of {@link ClusterMember}s.
 *
 * @param oldMembers to add to.
 * @param newMember  to add.
 * @return a new array containing the old members plus the new member.
 */
public static ClusterMember[] addMember(final ClusterMember[] oldMembers, final ClusterMember newMember)
{
    return ArrayUtil.add(oldMembers, newMember);
}