My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright 2011 LMAX Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lmax.disruptor;

/**
* Strategy contract for claiming the sequence of events in the {@link Sequencer} by event publishers.
*/
public interface ClaimStrategy
{
/**
* Get the size of the data structure used to buffer events.
*
* @return size of the underlying buffer.
*/
int getBufferSize();

/**
* Get the current claimed sequence.
*
* @return the current claimed sequence.
*/
long getSequence();

/**
* Is there available capacity in the buffer for the requested sequence.
*
* @param availableCapacity remaining in the buffer.
* @param dependentSequences to be checked for range.
* @return true if the buffer has capacity for the requested sequence.
*/
boolean hasAvailableCapacity(final int availableCapacity, final Sequence[] dependentSequences);

/**
* Claim the next sequence in the {@link Sequencer}.
* The caller should be held up until the claimed sequence is available by tracking the dependentSequences.
*
* @param dependentSequences to be checked for range.
* @return the index to be used for the publishing.
*/
long incrementAndGet(final Sequence[] dependentSequences);

/**
* Increment sequence by a delta and get the result.
* The caller should be held up until the claimed sequence batch is available by tracking the dependentSequences.
*
* @param delta to increment by.
* @param dependentSequences to be checked for range.
* @return the result after incrementing.
*/
long incrementAndGet(final int delta, final Sequence[] dependentSequences);

/**
* Set the current sequence value for claiming an event in the {@link Sequencer}
* The caller should be held up until the claimed sequence is available by tracking the dependentSequences.
*
* @param dependentSequences to be checked for range.
* @param sequence to be set as the current value.
*/
void setSequence(final long sequence, final Sequence[] dependentSequences);

/**
* Serialise publishers in sequence and set cursor to latest available sequence.
*
* @param sequence sequence to be applied
* @param cursor to serialise against.
* @param batchSize of the sequence.
*/
void serialisePublishing(final long sequence, final Sequence cursor, final int batchSize);

/**
* Atomically checks the available capacity of the ring buffer and claims the next sequence. Will
* throw InsufficientCapacityException if the capacity not available.
*
* @param availableCapacity the capacity that should be available before claiming the next slot
* @param delta the number of slots to claim
* @param gatingSequences the set of sequences to check to ensure capacity is available
* @return the slot after incrementing
* @throws InsufficientCapacityException thrown if capacity is not available
*/
long checkAndIncrement(int availableCapacity, int delta, Sequence[] gatingSequences)
throws InsufficientCapacityException;
}

Change log

r527 by mikeb01 on Mar 17, 2012   Diff
Add tryNext() to Sequencer.  Add
checkAndIncrement() to ClaimStrategy.
Introduce common super class for
MultithreadClaimStrategies.
Go to: 
Project members, sign in to write a code review

Older revisions

r473 by mjpt777 on Nov 9, 2011   Diff
Added timeout versions of next methods
on Sequencer for claiming next
sequences.
r469 by mjpt777 on Nov 2, 2011   Diff
Opened up claim and wait strategies so
user defined ones can be applied.
r464 by mjpt777 on Nov 1, 2011   Diff
Fully name claim and wait strategies.
All revisions of this file

File info

Size: 3693 bytes, 95 lines
Powered by Google Project Hosting