Unnamed: 0
int64 0
6.7k
| func
stringlengths 12
89.6k
| target
bool 2
classes | project
stringlengths 45
151
|
|---|---|---|---|
5,900
|
public interface GraphDefinition
{
Node create( GraphDatabaseService graphdb );
}
| false
|
community_graph-algo_src_test_java_common_GraphDefinition.java
|
5,901
|
public static enum MyRelTypes implements RelationshipType
{
R1, R2, R3
}
| false
|
community_graph-algo_src_test_java_common_Neo4jAlgoTestCase.java
|
5,902
|
public enum StandardGraphs implements GraphDefinition, RelationshipType
{
CROSS_PATHS_GRAPH
{
public Node create( GraphDatabaseService graphdb )
{
Node start = graphdb.createNode(), end = graphdb.createNode();
Node a = graphdb.createNode(), b = graphdb.createNode(), c = graphdb.createNode(), d = graphdb.createNode();
start.createRelationshipTo( a, this );
start.createRelationshipTo( b, this );
a.createRelationshipTo( c, this );
a.createRelationshipTo( d, this );
b.createRelationshipTo( c, this );
b.createRelationshipTo( d, this );
c.createRelationshipTo( end, this );
d.createRelationshipTo( end, this );
return end;
}
},
SMALL_CIRCLE
{
public Node create( GraphDatabaseService graphdb )
{
Node start = graphdb.createNode(), end = graphdb.createNode();
start.createRelationshipTo( end, this );
end.createRelationshipTo( start, this );
return end;
}
},
MATRIX_EXAMPLE
{
public Node create( GraphDatabaseService graphdb )
{
Node neo = graphdb.createNode();
neo.setProperty( "name", "Thomas Anderson" );
neo.setProperty( "age", 29 );
Node trinity = graphdb.createNode();
trinity.setProperty( "name", "Trinity" );
Node morpheus = graphdb.createNode();
morpheus.setProperty( "name", "Morpheus" );
morpheus.setProperty( "rank", "Captain" );
morpheus.setProperty( "occupation", "Total badass" );
Node cypher = graphdb.createNode();
cypher.setProperty( "name", "Cypher" );
cypher.setProperty( "last name", "Reagan" );
Node smith = graphdb.createNode();
smith.setProperty( "name", "Agent Smith" );
smith.setProperty( "version", "1.0b" );
smith.setProperty( "language", "C++" );
Node architect = graphdb.createNode();
architect.setProperty( "name", "The Architect" );
Relationship relationship;
relationship = neo.createRelationshipTo( morpheus,
StandardGraphs.MatrixTypes.KNOWS );
relationship = neo.createRelationshipTo( trinity,
StandardGraphs.MatrixTypes.KNOWS );
relationship = morpheus.createRelationshipTo( trinity,
StandardGraphs.MatrixTypes.KNOWS );
relationship.setProperty( "since", "a year before the movie" );
relationship.setProperty( "cooporates on", "The Nebuchadnezzar" );
relationship = trinity.createRelationshipTo( neo,
StandardGraphs.MatrixTypes.LOVES );
relationship.setProperty( "since", "meeting the oracle" );
relationship = morpheus.createRelationshipTo( cypher,
StandardGraphs.MatrixTypes.KNOWS );
relationship.setProperty( "disclosure", "public" );
relationship = cypher.createRelationshipTo( smith,
StandardGraphs.MatrixTypes.KNOWS );
relationship.setProperty( "disclosure", "secret" );
relationship = smith.createRelationshipTo( architect,
StandardGraphs.MatrixTypes.CODED_BY );
return neo;
}
};
public enum MatrixTypes implements RelationshipType
{
KNOWS,
CODED_BY,
LOVES
}
}
| false
|
community_graph-algo_src_test_java_common_StandardGraphs.java
|
5,903
|
public enum MatrixTypes implements RelationshipType
{
KNOWS,
CODED_BY,
LOVES
}
| false
|
community_graph-algo_src_test_java_common_StandardGraphs.java
|
5,904
|
enum FriendshipTypes implements RelationshipType
{
FRIEND,
LIVES_IN
}
| false
|
community_graph-matching_src_test_java_examples_TestSiteIndexExamples.java
|
5,905
|
private interface GraphDefinition<RESULT>
{
RESULT create( GraphDatabaseService graphdb );
}
| false
|
community_graph-matching_src_test_java_examples_TestSiteIndexExamples.java
|
5,906
|
private static enum MyRelTypes implements RelationshipType
{
R1,
R2,
R3,
hasRoleInGroup,
hasGroup,
hasRole
}
| false
|
community_graph-matching_src_test_java_matching_TestPatternMatching.java
|
5,907
|
public interface Adversary
{
/**
* Will randomly choose one of the given failures to throw, or not!
*/
void injectFailure( Class<? extends Throwable>... failureTypes );
/**
* Will randomly choose one of the given failures to throw, or return <code>true</code> if
* other kinds of mischeif should happen, or <code>false</code> if nothing bad should happen.
*/
boolean injectFailureOrMischief( Class<? extends Throwable>... failureTypes );
}
| false
|
community_kernel_src_test_java_org_neo4j_adversaries_Adversary.java
|
5,908
|
public static enum BackupRequestType implements RequestType<TheBackupInterface>
{
FULL_BACKUP( new TargetCaller<TheBackupInterface, Void>()
{
public Response<Void> call( TheBackupInterface master, RequestContext context,
ChannelBuffer input, ChannelBuffer target )
{
return master.fullBackup( new ToNetworkStoreWriter( target, new Monitors() ) );
}
}, Protocol.VOID_SERIALIZER ),
INCREMENTAL_BACKUP( new TargetCaller<TheBackupInterface, Void>()
{
public Response<Void> call( TheBackupInterface master, RequestContext context,
ChannelBuffer input, ChannelBuffer target )
{
return master.incrementalBackup( context );
}
}, Protocol.VOID_SERIALIZER )
;
@SuppressWarnings( "rawtypes" )
private final TargetCaller masterCaller;
@SuppressWarnings( "rawtypes" )
private final ObjectSerializer serializer;
@SuppressWarnings( "rawtypes" )
private BackupRequestType( TargetCaller masterCaller, ObjectSerializer serializer )
{
this.masterCaller = masterCaller;
this.serializer = serializer;
}
@SuppressWarnings( "rawtypes" )
public TargetCaller getTargetCaller()
{
return masterCaller;
}
@SuppressWarnings( "rawtypes" )
public ObjectSerializer getObjectSerializer()
{
return serializer;
}
public byte id()
{
return (byte) ordinal();
}
}
| false
|
enterprise_backup_src_main_java_org_neo4j_backup_BackupClient.java
|
5,909
|
public interface SPI
{
String getStoreDir();
StoreId getStoreId();
}
| false
|
enterprise_backup_src_main_java_org_neo4j_backup_BackupImpl.java
|
5,910
|
public interface Dependencies
{
Config getConfig();
XaDataSourceManager xaDataSourceManager();
GraphDatabaseAPI getGraphDatabaseAPI();
Logging logging();
KernelPanicEventGenerator kpeg();
Monitors monitors();
}
| false
|
enterprise_backup_src_main_java_org_neo4j_backup_OnlineBackupExtensionFactory.java
|
5,911
|
public interface BackupProvider
{
TheBackupInterface newBackup();
}
| false
|
enterprise_backup_src_main_java_org_neo4j_backup_OnlineBackupKernelExtension.java
|
5,912
|
public interface ServerInterface
{
void shutdown();
void awaitStarted();
}
| false
|
enterprise_backup_src_test_java_org_neo4j_backup_ServerInterface.java
|
5,913
|
public interface StartupChecker
{
boolean startupOk();
}
| false
|
enterprise_backup_src_test_java_org_neo4j_backup_TestBackup.java
|
5,914
|
public interface TheBackupInterface
{
Response<Void> fullBackup( StoreWriter writer );
Response<Void> incrementalBackup( RequestContext context );
}
| false
|
enterprise_backup_src_main_java_org_neo4j_backup_TheBackupInterface.java
|
5,915
|
enum VerificationLevel implements ConfigParam
{
NONE( null, null )
{
@Override
public void configure( Map<String, String> config )
{
// do nothing
}
},
VERIFYING( VerifyingTransactionInterceptorProvider.NAME, "true" ),
LOGGING( InconsistencyLoggingTransactionInterceptorProvider.NAME, DIFF.name() ),
FULL_WITH_LOGGING( InconsistencyLoggingTransactionInterceptorProvider.NAME, FULL.name() );
private final String interceptorName;
private final String configValue;
private VerificationLevel( String name, String value )
{
this.interceptorName = name;
this.configValue = value;
}
static VerificationLevel valueOf( boolean verification )
{
return verification ? VERIFYING : NONE;
}
@Override
public void configure( Map<String, String> config )
{
configure( config, configValue );
}
void configureWithDiffLog( Map<String, String> config, String targetFile )
{
configure( config, configValue + ";log=" + targetFile );
}
private void configure( Map<String, String> config, String value )
{
config.put( GraphDatabaseSettings.intercept_deserialized_transactions.name(), "true" );
config.put( TransactionInterceptorProvider.class.getSimpleName() + "." + interceptorName, value );
}
}
| false
|
enterprise_backup_src_main_java_org_neo4j_backup_VerificationLevel.java
|
5,916
|
public interface BindingListener
{
void listeningAt( URI me );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_BindingListener.java
|
5,917
|
public interface ClusterMonitor extends BindingNotifier, Heartbeat
{
void addClusterListener( ClusterListener listener);
void removeClusterListener( ClusterListener listener);
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_ClusterMonitor.java
|
5,918
|
public static interface SubGoal
{
boolean met();
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_Goal.java
|
5,919
|
public interface NetworkLatencyStrategy
{
public static long LOST = -1;
long messageDelay(Message<? extends MessageType> message, String serverIdTo);
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_NetworkLatencyStrategy.java
|
5,920
|
public interface ProtocolServerFactory
{
ProtocolServer newProtocolServer( InstanceId me, TimeoutStrategy timeouts, MessageSource input, MessageSender output,
AcceptorInstanceStore acceptorInstanceStore,
ElectionCredentialsProvider electionCredentialsProvider,
Executor stateMachineExecutor,
ObjectInputStreamFactory objectInputStreamFactory,
ObjectOutputStreamFactory objectOutputStreamFactory);
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_ProtocolServerFactory.java
|
5,921
|
public enum TestMessage
implements MessageType
{
message1, message2, message3, message4, message5;
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_StateMachinesTest.java
|
5,922
|
public enum TestState
implements State<List, TestMessage>
{
test
{
@Override
public State<?, ?> handle( List context, Message<TestMessage> message, MessageHolder outgoing ) throws Throwable
{
context.add(message.getMessageType());
switch ( message.getMessageType() )
{
case message1:
{
outgoing.offer( internal( TestMessage.message2 ) );
outgoing.offer( internal( TestMessage.message3 ) );
break;
}
case message2:
{
outgoing.offer( internal( TestMessage.message4 ) );
outgoing.offer( internal( TestMessage.message5 ) );
break;
}
}
return this;
}
};
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_StateMachinesTest.java
|
5,923
|
public interface Verifier<STATE>
{
/**
* Throws an {@link IllegalStateException} if it doesn't verify correctly.
* @param state the state to verify.
*/
void verify( STATE state );
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_Verifier.java
|
5,924
|
public interface Configuration
{
int getServerId();
HostnamePort getAddress();
List<HostnamePort> getInitialHosts();
String getClusterName();
boolean isAllowedToCreateCluster();
// Cluster timeout settings
long defaultTimeout(); // default is 5s
long heartbeatInterval(); // inherits defaultTimeout
long heartbeatTimeout(); // heartbeatInterval * 2 by default
long broadcastTimeout(); // default is 30s
long learnTimeout(); // inherits defaultTimeout
long paxosTimeout(); // inherits defaultTimeout
long phase1Timeout(); // inherits paxosTimeout
long phase2Timeout(); // inherits paxosTimeout
long joinTimeout(); // inherits defaultTimeout
long configurationTimeout(); // inherits defaultTimeout
long leaveTimeout(); // inherits paxosTimeout
long electionTimeout(); // inherits paxosTimeout
long clusterJoinTimeout(); // Whether to timeout the whole process or not
String name(); // Cluster client name, if any
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_client_ClusterClient.java
|
5,925
|
public interface Configuration
{
List<HostnamePort> getInitialHosts();
String getClusterName();
boolean isAllowedToCreateCluster();
long getClusterJoinTimeout();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_client_ClusterJoin.java
|
5,926
|
public interface BindingNotifier
{
public void addBindingListener( BindingListener listener );
public void removeBindingListener( BindingListener listener );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_BindingNotifier.java
|
5,927
|
public interface Configuration
{
HostnamePort clusterServer();
int defaultPort();
String name(); // Name of this cluster instance. Null in most cases, but tools may use e.g. "Backup"
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_NetworkReceiver.java
|
5,928
|
public interface NetworkChannelsListener
{
void listeningAt( URI me );
void channelOpened( URI to );
void channelClosed( URI to );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_NetworkReceiver.java
|
5,929
|
public interface Configuration
{
int defaultPort(); // This is the default port to try to connect to
int port(); // This is the port we are listening on
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_NetworkSender.java
|
5,930
|
public interface NetworkChannelsListener
{
void channelOpened( URI to );
void channelClosed( URI to );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_NetworkSender.java
|
5,931
|
public interface MessageHolder
{
void offer( Message<? extends MessageType> message );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_message_MessageHolder.java
|
5,932
|
public interface MessageProcessor
{
boolean process( Message<? extends MessageType> message );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_message_MessageProcessor.java
|
5,933
|
public interface MessageSender extends MessageProcessor
{
void process( List<Message<? extends MessageType>> message );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_message_MessageSender.java
|
5,934
|
public interface MessageSource
{
void addMessageProcessor( MessageProcessor messageProcessor );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_message_MessageSource.java
|
5,935
|
public interface MessageType
{
String name();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_com_message_MessageType.java
|
5,936
|
public enum TestMessage implements MessageType
{
helloWorld
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_com_message_NetworkSenderReceiverTest.java
|
5,937
|
public interface ClusterMemberAvailability
{
/**
* When a member has finished a transition to a particular role, i.e. master or slave,
* then it should call this which will broadcast the new status to the cluster.
*
* @param role
*/
void memberIsAvailable( String role, URI roleUri );
/**
* When a member is no longer available in a particular role it should call this
* to announce it to the other members of the cluster.
*
* @param role
*/
void memberIsUnavailable( String role );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_member_ClusterMemberAvailability.java
|
5,938
|
public interface ClusterMemberEvents
{
void addClusterMemberListener( ClusterMemberListener listener );
void removeClusterMemberListener( ClusterMemberListener listener );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_member_ClusterMemberEvents.java
|
5,939
|
public interface ClusterMemberListener
{
/**
* Called when new coordinator has been elected.
*
* @param coordinatorId the Id of the coordinator
*/
void coordinatorIsElected( InstanceId coordinatorId );
/**
* Called when a member announces that it is available to play a particular role, e.g. master or slave.
* After this it can be assumed that the member is ready to consume messages related to that role.
*
* @param role
* @param availableId the role connection information for the new role holder
* @param atUri the URI at which the instance is available at
*/
void memberIsAvailable( String role, InstanceId availableId, URI atUri );
/**
* Called when a member is no longer available for fulfilling a particular role.
*
* @param role The role for which the member is unavailable
* @param unavailableId The id of the member which became unavailable for that role
*/
void memberIsUnavailable( String role, InstanceId unavailableId );
void memberIsFailed( InstanceId instanceId );
void memberIsAlive( InstanceId instanceId );
public abstract class Adapter
implements ClusterMemberListener
{
@Override
public void coordinatorIsElected( InstanceId coordinatorId )
{
}
@Override
public void memberIsAvailable( String role, InstanceId availableId, URI atURI )
{
}
@Override
public void memberIsUnavailable( String role, InstanceId unavailableId )
{
}
@Override
public void memberIsFailed( InstanceId instanceId )
{
}
@Override
public void memberIsAlive( InstanceId instanceId )
{
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_member_ClusterMemberListener.java
|
5,940
|
public interface ConfigurationContext
{
InstanceId getMyId();
List<URI> getMemberURIs();
URI boundAt();
List<URI> getAcceptors();
Map<InstanceId,URI> getMembers();
InstanceId getCoordinator();
URI getUriForId( InstanceId id );
InstanceId getIdForUri(URI uri);
boolean isMe( InstanceId server );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_ConfigurationContext.java
|
5,941
|
public interface LoggingContext
{
StringLogger getLogger( Class loggingClass );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_LoggingContext.java
|
5,942
|
public interface TimeoutsContext
{
void setTimeout( Object key, Message<? extends MessageType> timeoutMessage );
void cancelTimeout( Object key );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_TimeoutsContext.java
|
5,943
|
public interface AtomicBroadcast
{
void broadcast( Payload payload );
void addAtomicBroadcastListener( AtomicBroadcastListener listener );
void removeAtomicBroadcastListener( AtomicBroadcastListener listener );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_AtomicBroadcast.java
|
5,944
|
public interface AtomicBroadcastListener
{
void receive( Payload value );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_AtomicBroadcastListener.java
|
5,945
|
public interface MapCommand
{
void execute( Map map );
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_protocol_atomicbroadcast_AtomicBroadcastMap.java
|
5,946
|
public interface ObjectInputStreamFactory
{
ObjectInputStream create( ByteArrayInputStream in ) throws IOException;
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_ObjectInputStreamFactory.java
|
5,947
|
public interface ObjectOutputStreamFactory
{
ObjectOutputStream create( ByteArrayOutputStream bout ) throws IOException;
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_ObjectOutputStreamFactory.java
|
5,948
|
public interface AcceptorContext
extends LoggingContext
{
AcceptorInstance getAcceptorInstance( InstanceId instanceId );
void promise( AcceptorInstance instance, long ballot );
void accept( AcceptorInstance instance, Object value );
void leave();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AcceptorContext.java
|
5,949
|
public interface AcceptorInstanceStore
{
AcceptorInstance getAcceptorInstance( InstanceId instanceId );
void promise( AcceptorInstance instance, long ballot );
void accept( AcceptorInstance instance, Object value );
void lastDelivered(InstanceId instanceId);
void clear();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AcceptorInstanceStore.java
|
5,950
|
public enum AcceptorMessage
implements MessageType
{
failure,
join, leave,
prepare, // phase 1a/1b
accept; // phase 2a/2b - timeout if resulting learn is not fast enough
public static class PrepareState
implements Serializable
{
private final long ballot;
public PrepareState( long ballot )
{
this.ballot = ballot;
}
public long getBallot()
{
return ballot;
}
@Override
public String toString()
{
return "PrepareState{" +
"ballot=" + ballot +
'}';
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
PrepareState that = (PrepareState) o;
if ( ballot != that.ballot )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return (int) (ballot ^ (ballot >>> 32));
}
}
public static class AcceptState
implements Serializable
{
private long ballot;
private Object value;
public AcceptState( long ballot, Object value )
{
this.ballot = ballot;
this.value = value;
}
public long getBallot()
{
return ballot;
}
public Object getValue()
{
return value;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
AcceptState that = (AcceptState) o;
if ( ballot != that.ballot )
{
return false;
}
if ( value != null ? !value.equals( that.value ) : that.value != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = (int) (ballot ^ (ballot >>> 32));
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AcceptorMessage.java
|
5,951
|
public enum AcceptorState
implements State<AcceptorContext, AcceptorMessage>
{
start
{
@Override
public AcceptorState handle( AcceptorContext context,
Message<AcceptorMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case join:
{
return acceptor;
}
}
return this;
}
},
acceptor
{
@Override
public AcceptorState handle( AcceptorContext context,
Message<AcceptorMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case prepare:
{
AcceptorMessage.PrepareState incomingState = message.getPayload();
InstanceId instanceId = new InstanceId( message );
// This creates the instance if not already present
AcceptorInstance localState = context.getAcceptorInstance( instanceId );
/*
* If the incoming messages has a ballot greater than the local one, send back a promise.
* This is always true for newly seen instances, the local state has ballot initialized
* to -1
*/
if ( incomingState.getBallot() >= localState.getBallot() )
{
context.promise( localState, incomingState.getBallot() );
outgoing.offer( message.copyHeadersTo( Message.respond( ProposerMessage.promise,
message, new ProposerMessage.PromiseState( incomingState.getBallot(),
localState.getValue() ) ), InstanceId.INSTANCE ) );
}
else
{
// Optimization - explicit reject
context.getLogger( AcceptorState.class ).debug("Rejecting prepare from "
+ message.getHeader( Message.FROM ) + " for instance "
+ message.getHeader( InstanceId.INSTANCE ) + " and ballot "
+ incomingState.getBallot() + " (i had a prepare state ballot = "
+ localState.getBallot() + ")" );
outgoing.offer( message.copyHeadersTo( Message.respond( ProposerMessage
.rejectPrepare, message,
new ProposerMessage.RejectPrepare( localState.getBallot() ) ),
InstanceId.INSTANCE ) );
}
break;
}
case accept:
{
// Task 4
AcceptorMessage.AcceptState acceptState = message.getPayload();
InstanceId instanceId = new InstanceId( message );
AcceptorInstance instance = context.getAcceptorInstance( instanceId );
if ( acceptState.getBallot() == instance.getBallot() )
{
context.accept( instance, acceptState.getValue() );
instance.accept( acceptState.getValue() );
outgoing.offer( message.copyHeadersTo( Message.respond( ProposerMessage.accepted,
message,
new ProposerMessage.AcceptedState() ), InstanceId.INSTANCE ) );
}
else
{
context.getLogger( AcceptorState.class ).debug( "Reject " + instanceId
+ " accept ballot:" + acceptState.getBallot() + " actual ballot:" +
instance.getBallot() );
outgoing.offer( message.copyHeadersTo( Message.respond( ProposerMessage
.rejectAccept, message,
new ProposerMessage.RejectAcceptState() ), InstanceId.INSTANCE ) );
}
break;
}
case leave:
{
context.leave();
return start;
}
}
return this;
}
},
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AcceptorState.java
|
5,952
|
public interface AtomicBroadcastContext
extends TimeoutsContext, ConfigurationContext
{
void addAtomicBroadcastListener( AtomicBroadcastListener listener );
void removeAtomicBroadcastListener( AtomicBroadcastListener listener );
void receive( final Payload value );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AtomicBroadcastContext.java
|
5,953
|
public enum AtomicBroadcastMessage
implements MessageType
{
// AtomicBroadcast API messages
broadcast, addAtomicBroadcastListener, removeAtomicBroadcastListener,
// Protocol implementation messages
entered, join, leave, // Group management
broadcastResponse, broadcastTimeout, failed; // Internal message created by implementation
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AtomicBroadcastMessage.java
|
5,954
|
public enum AtomicBroadcastState
implements State<AtomicBroadcastContext, AtomicBroadcastMessage>
{
start
{
@Override
public AtomicBroadcastState handle( AtomicBroadcastContext context,
Message<AtomicBroadcastMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case entered:
{
return broadcasting;
}
case join:
{
return joining;
}
default:
{
defaultHandling( context, message, outgoing );
}
}
return this;
}
},
joining
{
@Override
public State<?, ?> handle( AtomicBroadcastContext context,
Message<AtomicBroadcastMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case failed:
{
// Joining failed
outgoing.offer( internal( ClusterMessage.joinFailure,
new TimeoutException( "Could not join cluster" ) ) );
return start;
}
case broadcastResponse:
{
if ( message.getPayload() instanceof ClusterMessage.ConfigurationChangeState )
{
outgoing.offer( message.copyHeadersTo( internal( ClusterMessage.configurationChanged,
message.getPayload() ) ) );
}
break;
}
case entered:
{
return broadcasting;
}
default:
{
defaultHandling( context, message, outgoing );
}
}
return this;
}
},
broadcasting
{
@Override
public AtomicBroadcastState handle( AtomicBroadcastContext context,
Message<AtomicBroadcastMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case broadcast:
case failed:
{
org.neo4j.cluster.InstanceId coordinator = context.getCoordinator();
if ( coordinator != null )
{
URI coordinatorUri = context.getUriForId( coordinator );
outgoing.offer( message.copyHeadersTo(
to( ProposerMessage.propose, coordinatorUri, message.getPayload() ) ) );
context.setTimeout( "broadcast-" + message.getHeader( Message.CONVERSATION_ID ),
timeout( AtomicBroadcastMessage.broadcastTimeout, message,
message.getPayload() ) );
}
else
{
outgoing.offer( message.copyHeadersTo( internal( ProposerMessage.propose,
message.getPayload() ), Message.CONVERSATION_ID, org.neo4j.cluster.protocol
.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
break;
}
case broadcastResponse:
{
context.cancelTimeout( "broadcast-" + message.getHeader( Message.CONVERSATION_ID ) );
// TODO FILTER MESSAGES
if ( message.getPayload() instanceof ClusterMessage.ConfigurationChangeState )
{
outgoing.offer( message.copyHeadersTo( internal( ClusterMessage.configurationChanged,
message.getPayload() ) ) );
ClusterMessage.ConfigurationChangeState change = message.getPayload();
if ( change.getJoinUri() != null )
{
outgoing.offer( message.copyHeadersTo(
Message.internal( HeartbeatMessage.i_am_alive,
new HeartbeatMessage.IAmAliveState( change.getJoin() ) ),
Message.FROM ) );
}
}
else
{
context.receive( message.<Payload>getPayload() );
}
break;
}
case broadcastTimeout:
{
/*
* There is never the need to rebroadcast on broadcast timeout. The propose message always
* circulates on the wire until it is accepted - it comes back here when it fails just to
* check if the coordinator changed (look at "failed/broadcast" handling above).
*/
// outgoing.offer( internal( AtomicBroadcastMessage.broadcast, message.getPayload() ) );
break;
}
case leave:
{
return start;
}
default:
{
defaultHandling( context, message, outgoing );
}
}
return this;
}
};
private static void defaultHandling( AtomicBroadcastContext context, Message<AtomicBroadcastMessage> message,
MessageHolder outgoing )
{
switch ( message.getMessageType() )
{
case addAtomicBroadcastListener:
{
context.addAtomicBroadcastListener( (AtomicBroadcastListener) message.getPayload() );
break;
}
case removeAtomicBroadcastListener:
{
context.removeAtomicBroadcastListener( (AtomicBroadcastListener) message.getPayload() );
break;
}
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_AtomicBroadcastState.java
|
5,955
|
public interface LearnerContext
extends TimeoutsContext, LoggingContext, ConfigurationContext
{
long getLastDeliveredInstanceId();
void setLastDeliveredInstanceId( long lastDeliveredInstanceId );
long getLastLearnedInstanceId();
long getLastKnownLearnedInstanceInCluster();
void learnedInstanceId( long instanceId );
boolean hasDeliveredAllKnownInstances();
void leave();
PaxosInstance getPaxosInstance( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId );
AtomicBroadcastSerializer newSerializer();
Iterable<org.neo4j.cluster.InstanceId> getAlive();
void setNextInstanceId( long id );
void notifyLearnMiss( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId );
org.neo4j.cluster.InstanceId getLastKnownAliveUpToDateInstance();
void setLastKnownLearnedInstanceInCluster( long lastKnownLearnedInstanceInCluster, org.neo4j.cluster.InstanceId instanceId );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_LearnerContext.java
|
5,956
|
public enum LearnerMessage
implements MessageType
{
join, leave,
learn, learnRequest, learnFailed, learnTimedout, catchUp;
public static class LearnState
implements Serializable
{
private final Object value;
public LearnState( Object value )
{
this.value = value;
}
public Object getValue()
{
return value;
}
@Override
public String toString()
{
return value.toString();
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
LearnState that = (LearnState) o;
if ( value != null ? !value.equals( that.value ) : that.value != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return value != null ? value.hashCode() : 0;
}
}
public static class LearnRequestState
implements Serializable
{
public LearnRequestState()
{
}
@Override
public boolean equals( Object obj )
{
if(obj == null)
{
return false;
}
return getClass() == obj.getClass();
}
@Override
public int hashCode()
{
return 1;
}
@Override
public String toString()
{
return "Learn request";
}
}
public static class LearnFailedState
implements Serializable
{
public LearnFailedState()
{
}
@Override
public String toString()
{
return "Learn failed";
}
@Override
public int hashCode()
{
return 0;
}
@Override
public boolean equals( Object obj )
{
return obj instanceof LearnFailedState;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_LearnerMessage.java
|
5,957
|
public enum LearnerState
implements State<LearnerContext, LearnerMessage>
{
start
{
@Override
public LearnerState handle( LearnerContext context,
Message<LearnerMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case join:
{
return learner;
}
}
return this;
}
},
learner
{
@Override
public LearnerState handle( LearnerContext context,
Message<LearnerMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case learn:
{
LearnerMessage.LearnState learnState = message.getPayload();
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
StringLogger logger = context.getLogger( getClass() );
// Skip if we already know about this
if ( instanceId.getId() <= context.getLastDeliveredInstanceId() )
{
break;
}
context.learnedInstanceId( instanceId.getId() );
instance.closed( learnState.getValue(), message.getHeader( Message.CONVERSATION_ID ) );
/*
* The conditional below is simply so that no expensive deserialization will happen if we
* are not to print anything anyway if debug is not enabled.
*/
if ( logger.isDebugEnabled() )
{
String description;
if ( instance.value_2 instanceof Payload )
{
AtomicBroadcastSerializer atomicBroadcastSerializer = context.newSerializer();
description = atomicBroadcastSerializer.receive( (Payload) instance.value_2 ).toString();
}
else
{
description = instance.value_2.toString();
}
logger.debug(
"Learned and closed instance "+instance.id +
" from conversation " +
instance.conversationIdHeader +
" and the content was " +
description );
}
// If this is the next instance to be learned, then do so and check if we have anything
// pending to be learned
if ( instanceId.getId() == context.getLastDeliveredInstanceId() + 1 )
{
instance.delivered();
outgoing.offer( Message.internal( AtomicBroadcastMessage.broadcastResponse,
learnState.getValue() ) );
context.setLastDeliveredInstanceId( instanceId.getId() );
long checkInstanceId = instanceId.getId() + 1;
while ( (instance = context.getPaxosInstance( new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(
checkInstanceId ) )).isState( PaxosInstance.State.closed ) )
{
instance.delivered();
context.setLastDeliveredInstanceId( checkInstanceId );
Message<AtomicBroadcastMessage> learnMessage = Message.internal(
AtomicBroadcastMessage.broadcastResponse, instance.value_2 )
.setHeader( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instance.id.toString() )
.setHeader( Message.CONVERSATION_ID, instance.conversationIdHeader );
outgoing.offer( learnMessage );
checkInstanceId++;
}
if ( checkInstanceId == context.getLastKnownLearnedInstanceInCluster()
+ 1 )
{
// No hole - all is ok
// Cancel potential timeout, if one is active
context.cancelTimeout( "learn" );
}
else
{
// Found hole - we're waiting for this to be filled, i.e. timeout already set
context.getLogger( LearnerState.class ).debug( "*** HOLE! WAITING " +
"FOR " + (context.getLastDeliveredInstanceId() + 1) );
}
}
else
{
// Found hole - we're waiting for this to be filled, i.e. timeout already set
context.getLogger( LearnerState.class ).debug( "*** GOT " + instanceId
+ ", WAITING FOR " + (context.getLastDeliveredInstanceId() + 1) );
context.setTimeout( "learn", Message.timeout( LearnerMessage.learnTimedout,
message ) );
}
break;
}
case learnTimedout:
{
// Timed out waiting for learned values - send explicit request to everyone that is not failed
if ( !context.hasDeliveredAllKnownInstances() )
{
for ( long instanceId = context.getLastDeliveredInstanceId() + 1;
instanceId < context.getLastKnownLearnedInstanceInCluster();
instanceId++ )
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId id =
new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( instanceId );
PaxosInstance instance = context.getPaxosInstance( id );
if ( !instance.isState( PaxosInstance.State.closed ) && !instance.isState(
PaxosInstance.State.delivered ) )
{
for ( org.neo4j.cluster.InstanceId node : context.getAlive() )
{
URI nodeUri = context.getUriForId( node );
if ( !node.equals( context.getMyId() ) )
{
outgoing.offer( Message.to( LearnerMessage.learnRequest, nodeUri,
new LearnerMessage.LearnRequestState() ).setHeader(
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE,
id.toString() ) );
}
}
}
}
// Set another timeout
context.setTimeout( "learn", Message.timeout( LearnerMessage.learnTimedout,
message ) );
}
break;
}
case learnRequest:
{
// Someone wants to learn a value that we might have
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId =
new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
if ( instance.isState( PaxosInstance.State.closed )
|| instance.isState( PaxosInstance.State.delivered ) )
{
outgoing.offer( Message.respond( LearnerMessage.learn, message,
new LearnerMessage.LearnState( instance.value_2 ) ).
setHeader( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString() ).
setHeader( Message.CONVERSATION_ID, instance.conversationIdHeader ) );
}
else
{
context.notifyLearnMiss(instanceId);
outgoing.offer( message.copyHeadersTo( Message.respond( LearnerMessage.learnFailed,
message,
new LearnerMessage.LearnFailedState() ), org.neo4j.cluster.protocol
.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
break;
}
case learnFailed:
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
if ( !(instance.isState( PaxosInstance.State.closed ) || instance.isState( PaxosInstance
.State.delivered )) )
{
List<URI> nodes = context.getMemberURIs();
URI learnDeniedNode = new URI( message.getHeader( Message.FROM ) );
int nextPotentialLearnerIndex = (nodes.indexOf( learnDeniedNode ) + 1) % nodes.size();
URI learnerNode = nodes.get( nextPotentialLearnerIndex );
outgoing.offer( message.copyHeadersTo( Message.to( LearnerMessage.learnRequest,
learnerNode,
new LearnerMessage.LearnRequestState() ), org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
break;
}
case catchUp:
{
Long catchUpTo = message.getPayload();
if ( context.getLastKnownLearnedInstanceInCluster() < catchUpTo )
{
context.setNextInstanceId(catchUpTo + 1);
// Try to get up to date
for ( long instanceId = context.getLastLearnedInstanceId() + 1;
instanceId <= catchUpTo; instanceId++ )
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId id = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( instanceId );
PaxosInstance instance = context.getPaxosInstance( id );
if ( !instance.isState( PaxosInstance.State.closed ) && !instance.isState( PaxosInstance.State.delivered ) )
{
URI nodeUri = context.getUriForId( context.getLastKnownAliveUpToDateInstance() );
outgoing.offer( Message.to( LearnerMessage.learnRequest,
nodeUri,
new LearnerMessage.LearnRequestState() ).setHeader(
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE,
id.toString() ) );
context.setTimeout( "learn",
Message.timeout( LearnerMessage.learnTimedout, message ) );
break;
}
}
context.setLastKnownLearnedInstanceInCluster( catchUpTo,
context.getIdForUri( new URI(message.getHeader( Message.FROM )) ) );
}
break;
}
case leave:
{
context.leave();
return start;
}
}
return this;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_LearnerState.java
|
5,958
|
enum State
{
empty,
p1_pending,
p1_ready,
p2_pending,
closed,
delivered;
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_PaxosInstance.java
|
5,959
|
public interface ProposerContext
extends TimeoutsContext, LoggingContext, ConfigurationContext
{
InstanceId newInstanceId( );
PaxosInstance getPaxosInstance( InstanceId instanceId );
void pendingValue( Message message );
void bookInstance( InstanceId instanceId, Message message );
int nrOfBookedInstances();
boolean canBookInstance();
Message getBookedInstance( InstanceId id );
Message<ProposerMessage> unbookInstance( InstanceId id );
void patchBookedInstances( ClusterMessage.ConfigurationChangeState value );
int getMinimumQuorumSize( List<URI> acceptors );
boolean hasPendingValues();
Message popPendingValue();
void leave();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_ProposerContext.java
|
5,960
|
public enum ProposerMessage
implements MessageType
{
join, leave,
phase1Timeout,
propose, // If no accept message is sent out, it means not enough promises have come in
promise, rejectPrepare, rejectPropose2, // phase 1b
phase2Timeout,
accepted, rejectAccept; // phase 2b
public static class PromiseState
implements Serializable
{
private long ballot;
private Object value;
public PromiseState( long ballot, Object value )
{
this.ballot = ballot;
this.value = value;
}
public long getBallot()
{
return ballot;
}
public Object getValue()
{
return value;
}
@Override
public String toString()
{
return "PromiseState{" +
"ballot=" + ballot +
", value=" + value +
'}';
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
PromiseState that = (PromiseState) o;
if ( ballot != that.ballot )
{
return false;
}
if ( value != null ? !value.equals( that.value ) : that.value != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = (int) (ballot ^ (ballot >>> 32));
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
}
public static class RejectPrepare
implements Serializable
{
private long ballot;
public RejectPrepare( long ballot )
{
this.ballot = ballot;
}
public long getBallot()
{
return ballot;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
RejectPrepare that = (RejectPrepare) o;
if ( ballot != that.ballot )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return (int) (ballot ^ (ballot >>> 32));
}
}
public static class RejectAcceptState
implements Serializable
{
public RejectAcceptState()
{
}
@Override
public boolean equals( Object obj )
{
return obj instanceof RejectAcceptState;
}
@Override
public int hashCode()
{
return 0;
}
}
public static class AcceptedState
implements Serializable
{
public AcceptedState()
{
}
@Override
public boolean equals( Object obj )
{
return obj instanceof AcceptedState;
}
@Override
public int hashCode()
{
return 0;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_ProposerMessage.java
|
5,961
|
public enum ProposerState
implements State<ProposerContext, ProposerMessage>
{
start
{
@Override
public ProposerState handle( ProposerContext context,
Message<ProposerMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case join:
{
return proposer;
}
}
return this;
}
},
proposer
{
@Override
public ProposerState handle( ProposerContext context,
Message<ProposerMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case propose:
{
propose( context, message, outgoing, determineAcceptorSet( message, context ) );
break;
}
case rejectPrepare:
{
// Denial of prepare
ProposerMessage.RejectPrepare rejectPropose = message.getPayload();
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
context.getLogger( ProposerState.class ).debug( "Propose for instance " + instance
+ " rejected from " + message.getHeader( Message.FROM ) + " with ballot "
+ rejectPropose.getBallot() );
if ( instance.isState( PaxosInstance.State.p1_pending ) )
{
long ballot = instance.ballot;
while ( ballot <= rejectPropose.getBallot() )
{
ballot += 1000; // Make sure we win next time
}
instance.phase1Timeout( ballot );
context.getLogger( ProposerState.class ).debug(
"Reproposing instance " + instance + " at ballot " + instance.ballot
+ " after rejectPrepare" );
for ( URI acceptor : instance.getAcceptors() )
{
outgoing.offer( message.copyHeadersTo( Message.to( AcceptorMessage.prepare,
acceptor, new AcceptorMessage.PrepareState( ballot ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
assert instance.value_1 == null : "value_1 should have been null at this point";
Object payload = context.getBookedInstance( instanceId ).getPayload();
assert payload != null : "Should have a booked instance payload for " + instanceId;
// This will reset the phase1Timeout if existing
context.setTimeout( instanceId, message.copyHeadersTo( Message.timeout(
ProposerMessage.phase1Timeout, message, payload ), org.neo4j.cluster.protocol
.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
break;
}
case phase1Timeout:
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
if ( instance.isState( PaxosInstance.State.p1_pending ) )
{
if ( instance.ballot > 10000 )
{
context.getLogger( ProposerState.class ).warn( "Propose failed due to phase 1 " +
"timeout" );
// Fail this propose
Message originalMessage = context.getBookedInstance( instance.id );
// Also make sure that all headers are copied over
outgoing.offer( originalMessage.copyHeadersTo(
Message.internal( AtomicBroadcastMessage.failed,
originalMessage.getPayload() ) ) );
context.cancelTimeout( instanceId );
}
else
{
long ballot = instance.ballot + 1000;
instance.phase1Timeout( ballot );
for ( URI acceptor : instance.getAcceptors() )
{
outgoing.offer( message.copyHeadersTo( Message.to( AcceptorMessage.prepare,
acceptor, new AcceptorMessage.PrepareState( ballot ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
context.setTimeout( instanceId, message.copyHeadersTo( Message.timeout(
ProposerMessage.phase1Timeout, message, message.getPayload() ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
}
else if ( instance.isState( PaxosInstance.State.closed ) || instance.isState(
PaxosInstance.State.delivered ) )
{
// Retry
Message oldMessage = context.unbookInstance( instance.id );
context.getLogger( getClass() ).debug( "Retrying instance " + instance.id +
" with message " + message.getPayload() +
". Previous instance was " + oldMessage );
outgoing.offer( Message.internal( ProposerMessage.propose, message.getPayload() ) );
}
break;
}
case promise:
{
// P
ProposerMessage.PromiseState promiseState = message.getPayload();
PaxosInstance instance = context.getPaxosInstance( new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message ) );
if ( instance.isState( PaxosInstance.State.p1_pending ) && instance.ballot ==
promiseState.getBallot() )
{
instance.promise( promiseState );
if ( instance.isPromised( context.getMinimumQuorumSize( instance.getAcceptors() ) ) )
{
context.cancelTimeout( instance.id );
// No promises contained a value
Object readyValue = instance.value_2 == null ?
context.getBookedInstance( instance.id ).getPayload() : instance
.value_2;
if ( instance.value_1 == null )
{
// R0
instance.ready( readyValue, true );
}
else
{
// R1
if ( instance.value_2 == null )
{
// Another value was already associated with this instance. Push value
// back onto pending list
context.pendingValue( context.unbookInstance( instance.id ) );
instance.ready( instance.value_1, false );
}
else if ( instance.value_1.equals( readyValue ) )
{
instance.ready( instance.value_2, instance.clientValue );
}
else if ( instance.clientValue )
{
// Another value was already associated with this instance. Push value
// back onto pending list
context.pendingValue( context.unbookInstance( instance.id ) );
instance.ready( instance.value_1, false );
}
else
{
// Another value was already associated with this instance. Push value
// back onto pending list
context.pendingValue( context.unbookInstance( instance.id ) );
instance.ready( instance.value_1, false );
}
}
// E: Send to Acceptors
instance.pending();
for ( URI acceptor : instance.getAcceptors() )
{
outgoing.offer( message.copyHeadersTo( Message.to( AcceptorMessage.accept,
acceptor,
new AcceptorMessage.AcceptState( instance.ballot,
instance.value_2 ) ), org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
context.setTimeout( instance.id,
message.copyHeadersTo( Message.timeout( ProposerMessage.phase2Timeout,
message, readyValue ), org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
else
{
}
}
else
{
}
break;
}
case rejectAccept:
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
if ( instance.isState( PaxosInstance.State.p2_pending ) )
{
ProposerMessage.RejectAcceptState state = message.getPayload();
instance.rejected( state );
if ( !instance.isAccepted( context.getMinimumQuorumSize( instance.getAcceptors() ) ) )
{
context.cancelTimeout( instanceId );
context.getLogger( ProposerState.class ).warn( "Accept rejected:" +
instance.state );
if ( instance.clientValue )
{
Message copyWithValue = Message.internal( ProposerMessage.propose,
instance.value_2 );
message.copyHeadersTo( copyWithValue );
propose( context, copyWithValue, outgoing, instance.getAcceptors() );
}
}
}
break;
}
case phase2Timeout:
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
PaxosInstance instance = context.getPaxosInstance( instanceId );
if ( instance.isState( PaxosInstance.State.p2_pending ) )
{
long ballot = instance.ballot + 1000;
instance.phase2Timeout( ballot );
for ( URI acceptor : instance.getAcceptors() )
{
outgoing.offer( message.copyHeadersTo( Message.to( AcceptorMessage.prepare,
acceptor, new AcceptorMessage.PrepareState( ballot ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
context.setTimeout( instanceId, message.copyHeadersTo( Message.timeout(
ProposerMessage.phase1Timeout, message, message.getPayload() ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
else if ( instance.isState( PaxosInstance.State.closed )
|| instance.isState( PaxosInstance.State.delivered ) )
{
outgoing.offer( message.copyHeadersTo( Message.internal( ProposerMessage.propose,
message.getPayload() ) ) );
}
break;
}
case accepted:
{
PaxosInstance instance = context.getPaxosInstance( new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(
message ) );
if ( instance.isState( PaxosInstance.State.p2_pending ) )
{
ProposerMessage.AcceptedState acceptedState = message.getPayload();
instance.accepted( acceptedState );
// Value has been accepted! Now distribute to all learners
if ( instance.accepts.size() >= context.getMinimumQuorumSize( instance.getAcceptors()
) )
{
context.cancelTimeout( instance.id );
// Might have to extra-tell myself if not yet officially part of cluster
if ( instance.value_2 instanceof ClusterMessage.ConfigurationChangeState )
{
context.patchBookedInstances( (ClusterMessage.ConfigurationChangeState) instance.value_2);
ClusterMessage.ConfigurationChangeState state = (ClusterMessage
.ConfigurationChangeState) instance.value_2;
// TODO getLearners might return wrong list if another join happens at the
// same time
// Proper fix is to wait with this learn until we have learned all previous
// configuration changes
// TODO Fix this to use InstanceId instead of URI
for ( URI learner : context.getMemberURIs() )
{
if ( learner.equals( context.boundAt() ) )
{
outgoing.offer( message.copyHeadersTo( Message.internal( LearnerMessage
.learn, new LearnerMessage.LearnState( instance.value_2 ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
else
{
outgoing.offer( message.copyHeadersTo( Message.to( LearnerMessage
.learn, learner,
new LearnerMessage.LearnState( instance.value_2 ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
}
// Tell joiner of this cluster configuration change
if ( state.getJoin() != null )
{
outgoing.offer( message.copyHeadersTo( Message.to( LearnerMessage
.learn, state.getJoinUri(),
new LearnerMessage.LearnState( instance.value_2 ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
}
else
{
// Tell learners
for ( URI learner : context.getMemberURIs() )
{
outgoing.offer( message.copyHeadersTo( Message.to( LearnerMessage
.learn, learner,
new LearnerMessage.LearnState( instance.value_2 ) ),
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) );
}
}
context.unbookInstance( instance.id );
// Check if we have anything pending - try to start process for it
if ( context.hasPendingValues() && context.canBookInstance() )
{
Message proposeMessage = context.popPendingValue();
context.getLogger( ProposerState.class ).debug( "Restarting "
+ proposeMessage + " booked:"
+ context.nrOfBookedInstances() );
outgoing.offer( proposeMessage );
}
}
} else
{
context.getLogger( ProposerState.class ).debug( "Instance receiving an accepted is in the wrong state:"+instance );
}
break;
}
case leave:
{
context.leave();
return start;
}
}
return this;
}
};
private static void propose( ProposerContext context, Message message, MessageHolder outgoing,
List<URI> acceptors )
{
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId;
if ( message.hasHeader( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE ) )
{
instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( message );
}
else
{
instanceId = context.newInstanceId();
message.setHeader( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString() );
context.bookInstance( instanceId, message );
}
long ballot = 1000 + context.getMyId().toIntegerIndex(); // First server will have first ballot id be 1001
PaxosInstance instance = context.getPaxosInstance( instanceId );
/*
* If the instance already has an acceptor set, use that. This ensures that patched acceptor sets, for example,
* are respected.
*/
if ( instance.getAcceptors() != null )
{
acceptors = instance.getAcceptors();
}
if ( !(instance.isState( PaxosInstance.State.closed ) || instance.isState( PaxosInstance.State.delivered )) )
{
instance.propose( ballot, acceptors );
for ( URI acceptor : acceptors )
{
outgoing.offer( Message.to( AcceptorMessage.prepare, acceptor, new AcceptorMessage.PrepareState(
ballot ) ).setHeader( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString() ) );
}
context.setTimeout( instanceId, Message.timeout( ProposerMessage.phase1Timeout, message,
message.getPayload() ).setHeader( org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString() ) );
}
else
{
// Wait with this value - we have our hands full right now
context.pendingValue( message );
}
}
private static List<URI> determineAcceptorSet( Message<ProposerMessage> message, ProposerContext context )
{
Object payload = message.getPayload();
if ( payload instanceof ClusterMessage.ConfigurationChangeState )
{
ClusterMessage.ConfigurationChangeState state = message.getPayload();
List<URI> acceptors = context.getAcceptors();
Map<org.neo4j.cluster.InstanceId, URI> currentMembers = context.getMembers();
// Never include node that is leaving
if ( state.getLeave() != null )
{
acceptors = new ArrayList<URI>( acceptors );
acceptors.remove( currentMembers.get(state.getLeave()) );
}
if ( state.getJoin() != null && currentMembers.containsKey( state.getJoin() ) )
{
acceptors.remove( currentMembers.get( state.getJoin() ) );
if ( !acceptors.contains( state.getJoinUri() ) )
{
acceptors.add( state.getJoinUri() );
}
}
return acceptors;
}
else
{
return context.getAcceptors();
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_ProposerState.java
|
5,962
|
interface WinnerStrategy
{
org.neo4j.cluster.InstanceId pickWinner( Collection<Vote> votes );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_atomicbroadcast_multipaxos_context_ElectionContextImpl.java
|
5,963
|
public interface Cluster
{
void create(String clusterName);
Future<ClusterConfiguration> join(String clusterName, URI... otherServerUrls);
void leave();
void addClusterListener( ClusterListener listener);
void removeClusterListener( ClusterListener listener);
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_cluster_Cluster.java
|
5,964
|
public interface ClusterContext
extends LoggingContext, TimeoutsContext, ConfigurationContext
{
// Cluster API
void addClusterListener( ClusterListener listener );
void removeClusterListener( ClusterListener listener );
// Implementation
void created( String name );
void joining( String name, Iterable<URI> instanceList );
void acquiredConfiguration( final Map<InstanceId, URI> memberList, final Map<String, InstanceId> roles );
void joined();
void left();
void joined( final InstanceId instanceId, final URI atURI );
void left( final InstanceId node );
void elected( final String roleName, final InstanceId instanceId );
void unelected( final String roleName, final InstanceId instanceId );
ClusterConfiguration getConfiguration();
boolean isElectedAs( String roleName );
boolean isInCluster();
Iterable<URI> getJoiningInstances();
ObjectOutputStreamFactory getObjectOutputStreamFactory();
ObjectInputStreamFactory getObjectInputStreamFactory();
List<ClusterMessage.ConfigurationRequestState> getDiscoveredInstances();
void setBoundAt( URI boundAt );
void joinDenied( ConfigurationResponseState configurationResponseState );
boolean hasJoinBeenDenied();
ConfigurationResponseState getJoinDeniedConfigurationResponseState();
Iterable<InstanceId> getOtherInstances();
boolean isInstanceJoiningFromDifferentUri( InstanceId joiningId, URI joiningUri );
void instanceIsJoining( InstanceId joiningId, URI uri );
String myName();
void discoveredLastReceivedInstanceId( long id );
boolean isCurrentlyAlive( InstanceId joiningId );
long getLastDeliveredInstanceId();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_cluster_ClusterContext.java
|
5,965
|
public interface ClusterListener
{
/**
* When I enter the cluster as a member, this callback notifies me
* that this has been agreed upon by the entire cluster.
*
* @param clusterConfiguration
*/
void enteredCluster( ClusterConfiguration clusterConfiguration );
/**
* When I leave the cluster, this callback notifies me
* that this has been agreed upon by the entire cluster.
*/
void leftCluster();
/**
* When another instance joins as a member, this callback is invoked
*
* @param member
*/
void joinedCluster( InstanceId instanceId, URI member );
/**
* When another instance leaves the cluster, this callback is invoked.
* Implicitly, any roles that this member had, are revoked.
*
* @param member
*/
void leftCluster( InstanceId instanceId );
/**
* When a member (including potentially myself) has been elected to a particular role, this callback is invoked.
* Combine this callback with the leftCluster to keep track of current set of role->member mappings.
*
* @param role
* @param electedMember
*/
void elected( String role, InstanceId instanceId, URI electedMember );
void unelected( String role, InstanceId instanceId, URI electedMember );
public abstract class Adapter
implements ClusterListener
{
@Override
public void enteredCluster( ClusterConfiguration clusterConfiguration )
{
}
@Override
public void joinedCluster( InstanceId instanceId, URI member )
{
}
@Override
public void leftCluster( InstanceId instanceId )
{
}
@Override
public void leftCluster()
{
}
@Override
public void elected( String role, InstanceId instanceId, URI electedMember )
{
}
@Override
public void unelected( String role, InstanceId instanceId, URI electedMember )
{
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_cluster_ClusterListener.java
|
5,966
|
public enum ClusterMessage
implements MessageType
{
// Method messages
create, createResponse, join, joinResponse, leave, leaveResponse,
addClusterListener, removeClusterListener,
// Protocol messages
joining, joiningTimeout,
configurationRequest, configurationResponse, configurationTimeout, configurationChanged,
joinDenied, joinFailure, leaveTimedout;
public static class ConfigurationRequestState implements Serializable, Comparable<ConfigurationRequestState>
{
private static final long serialVersionUID = -221752558518247157L;
private InstanceId joiningId;
private URI joiningUri;
public ConfigurationRequestState( InstanceId joiningId, URI joiningUri )
{
this.joiningId = joiningId;
this.joiningUri = joiningUri;
}
public InstanceId getJoiningId()
{
return joiningId;
}
public URI getJoiningUri()
{
return joiningUri;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ConfigurationRequestState that = (ConfigurationRequestState) o;
if ( !joiningId.equals( that.joiningId ) )
{
return false;
}
if ( !joiningUri.equals( that.joiningUri ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = joiningId.hashCode();
result = 31 * result + joiningUri.hashCode();
return result;
}
@Override
public int compareTo( ConfigurationRequestState o )
{
return this.joiningId.compareTo( o.joiningId );
}
@Override
public String toString()
{
return joiningId + ":" + joiningUri;
}
}
public static class ConfigurationResponseState
implements Serializable
{
private final Map<InstanceId, URI> nodes;
private final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId latestReceivedInstanceId;
private final Map<String, InstanceId> roles;
private final String clusterName;
public ConfigurationResponseState( Map<String, InstanceId> roles, Map<InstanceId, URI> nodes,
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId latestReceivedInstanceId,
String clusterName )
{
this.roles = roles;
this.nodes = nodes;
this.latestReceivedInstanceId = latestReceivedInstanceId;
this.clusterName = clusterName;
}
public Map<InstanceId, URI> getMembers()
{
return nodes;
}
public Map<String, InstanceId> getRoles()
{
return roles;
}
public org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId getLatestReceivedInstanceId()
{
return latestReceivedInstanceId;
}
public String getClusterName()
{
return clusterName;
}
public ConfigurationResponseState snapshot()
{
return new ConfigurationResponseState( new HashMap<>(roles), new HashMap<>(nodes),
latestReceivedInstanceId, clusterName );
}
@Override
public String toString()
{
return "ConfigurationResponseState{" +
"nodes=" + nodes +
", latestReceivedInstanceId=" + latestReceivedInstanceId +
", roles=" + roles +
", clusterName='" + clusterName + '\'' +
'}';
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ConfigurationResponseState that = (ConfigurationResponseState) o;
if ( clusterName != null ? !clusterName.equals( that.clusterName ) : that.clusterName != null )
{
return false;
}
if ( latestReceivedInstanceId != null ? !latestReceivedInstanceId.equals( that.latestReceivedInstanceId )
: that.latestReceivedInstanceId != null )
{
return false;
}
if ( nodes != null ? !nodes.equals( that.nodes ) : that.nodes != null )
{
return false;
}
if ( roles != null ? !roles.equals( that.roles ) : that.roles != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = nodes != null ? nodes.hashCode() : 0;
result = 31 * result + (latestReceivedInstanceId != null ? latestReceivedInstanceId.hashCode() : 0);
result = 31 * result + (roles != null ? roles.hashCode() : 0);
result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
return result;
}
}
public static class ConfigurationChangeState
implements Serializable
{
private InstanceId join;
private URI joinUri;
private InstanceId leave;
private String roleWon;
private InstanceId winner;
private String roleLost;
private InstanceId loser;
public void join( InstanceId join, URI joinUri )
{
this.join = join;
this.joinUri = joinUri;
}
public void leave( InstanceId uri )
{
this.leave = uri;
}
public void elected( String role, InstanceId winner )
{
this.roleWon = role;
this.winner = winner;
}
public void unelected( String role, InstanceId unelected )
{
roleLost = role;
loser = unelected;
}
public InstanceId getJoin()
{
return join;
}
public URI getJoinUri()
{
return joinUri;
}
public InstanceId getLeave()
{
return leave;
}
public void apply( ClusterContext context )
{
if ( join != null )
{
context.joined( join, joinUri );
}
if ( leave != null )
{
context.left( leave );
}
if ( roleWon != null )
{
context.elected( roleWon, winner );
}
if ( roleLost != null )
{
context.unelected( roleLost, loser );
}
}
public boolean isLeaving( InstanceId me )
{
return me.equals( leave );
}
@Override
public String toString()
{
if ( join != null )
{
return "Change cluster config, join:" + join;
}
if ( leave != null )
{
return "Change cluster config, leave:" + leave;
}
if (roleWon != null)
return "Change cluster config, elected:" + winner + " as " + roleWon;
else
return "Change cluster config, unelected:" + loser + " as " + roleWon;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ConfigurationChangeState that = (ConfigurationChangeState) o;
if ( join != null ? !join.equals( that.join ) : that.join != null )
{
return false;
}
if ( joinUri != null ? !joinUri.equals( that.joinUri ) : that.joinUri != null )
{
return false;
}
if ( leave != null ? !leave.equals( that.leave ) : that.leave != null )
{
return false;
}
if ( loser != null ? !loser.equals( that.loser ) : that.loser != null )
{
return false;
}
if ( roleLost != null ? !roleLost.equals( that.roleLost ) : that.roleLost != null )
{
return false;
}
if ( roleWon != null ? !roleWon.equals( that.roleWon ) : that.roleWon != null )
{
return false;
}
if ( winner != null ? !winner.equals( that.winner ) : that.winner != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = join != null ? join.hashCode() : 0;
result = 31 * result + (joinUri != null ? joinUri.hashCode() : 0);
result = 31 * result + (leave != null ? leave.hashCode() : 0);
result = 31 * result + (roleWon != null ? roleWon.hashCode() : 0);
result = 31 * result + (winner != null ? winner.hashCode() : 0);
result = 31 * result + (roleLost != null ? roleLost.hashCode() : 0);
result = 31 * result + (loser != null ? loser.hashCode() : 0);
return result;
}
}
public static class ConfigurationTimeoutState
{
private final int remainingPings;
public ConfigurationTimeoutState( int remainingPings)
{
this.remainingPings = remainingPings;
}
public int getRemainingPings()
{
return remainingPings;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ConfigurationTimeoutState that = (ConfigurationTimeoutState) o;
if ( remainingPings != that.remainingPings )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return remainingPings;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_cluster_ClusterMessage.java
|
5,967
|
public interface ClusterTestScript
{
int rounds();
void tick( long time );
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_protocol_cluster_ClusterMockTest.java
|
5,968
|
public interface ClusterTestScript
{
void tick( long time );
long getLength();
}
| false
|
enterprise_cluster_src_test_java_org_neo4j_cluster_protocol_cluster_ClusterNetworkTest.java
|
5,969
|
public enum ClusterState
implements State<ClusterContext, ClusterMessage>
{
start
{
@Override
public State<?, ?> handle( ClusterContext context, Message<ClusterMessage> message,
MessageHolder outgoing ) throws Throwable
{
switch ( message.getMessageType() )
{
case addClusterListener:
{
context.addClusterListener( message.<ClusterListener>getPayload() );
break;
}
case removeClusterListener:
{
context.removeClusterListener( message.<ClusterListener>getPayload() );
break;
}
case create:
{
String name = message.getPayload();
context.getLogger( ClusterState.class ).info( "Creating cluster: " + name );
context.created( name );
return entered;
}
case join:
{
// Send configuration request to all instances
Object[] args = message.<Object[]>getPayload();
String name = ( String ) args[0];
URI[] clusterInstanceUris = ( URI[] ) args[1];
context.joining( name, Iterables.<URI,URI>iterable( clusterInstanceUris ) );
for ( URI potentialClusterInstanceUri : clusterInstanceUris )
{
outgoing.offer( to( ClusterMessage.configurationRequest,
potentialClusterInstanceUri,
new ClusterMessage.ConfigurationRequestState( context.getMyId(), context.boundAt() ) ) );
}
context.setTimeout( "discovery",
timeout( ClusterMessage.configurationTimeout, message,
new ClusterMessage.ConfigurationTimeoutState(
/*
* The time when this becomes relevant is if indeed there are
* other instances present in the configuration. If there aren't
* we won't wait for them anyway and only this delay prevents us
* from going ahead and creating the cluster. We still wait a bit
* though because even if we don't have them configured they still
* might contact us.
* If, on the other hand, we have some configured, then we won't
* startup anyway until half are available. So this delay doesn't
* enter into it anyway.
* In summary, this offers no upside if there are configured
* instances
* and causes unnecessary delay if we are supposed to go ahead and
* create the cluster.
*/
1 ) ) );
return discovery;
}
}
return this;
}
},
discovery
{
@Override
public State<?, ?> handle( ClusterContext context, Message<ClusterMessage> message,
MessageHolder outgoing ) throws Throwable
{
List<ClusterMessage.ConfigurationRequestState> discoveredInstances = context.getDiscoveredInstances();
switch ( message.getMessageType() )
{
case configurationResponse:
{
context.cancelTimeout( "discovery" );
ClusterMessage.ConfigurationResponseState state = message.getPayload();
context.getLogger( ClusterState.class ).info( "Joining cluster " + state.getClusterName() );
if ( !context.getConfiguration().getName().equals( state.getClusterName() ) )
{
context.getLogger( ClusterState.class ).warn( "Joined cluster name is different than " +
"the one configured. Expected " + context.getConfiguration().getName() +
", got " + state.getClusterName() + "." );
}
HashMap<InstanceId, URI> memberList = new HashMap<InstanceId, URI>( state.getMembers() );
context.discoveredLastReceivedInstanceId( state.getLatestReceivedInstanceId().getId() );
context.acquiredConfiguration( memberList, state.getRoles() );
if ( !memberList.containsKey( context.getMyId() ) ||
!memberList.get( context.getMyId() ).equals( context.boundAt() ) )
{
context.getLogger( ClusterState.class ).info( String.format( "%s joining:%s, " +
"last delivered:%d", context.getMyId().toString(),
context.getConfiguration().toString(),
state.getLatestReceivedInstanceId().getId() ) );
ClusterMessage.ConfigurationChangeState newState = new ClusterMessage
.ConfigurationChangeState();
newState.join(context.getMyId(), context.boundAt());
// Let the coordinator propose this if possible
InstanceId coordinator = state.getRoles().get( ClusterConfiguration.COORDINATOR );
if ( coordinator != null )
{
URI coordinatorUri = context.getConfiguration().getUriForId( coordinator );
outgoing.offer( to( ProposerMessage.propose, coordinatorUri, newState ) );
}
else
{
outgoing.offer( to( ProposerMessage.propose, new URI( message.getHeader(
Message.FROM ) ), newState ) );
}
context.getLogger( ClusterState.class ).debug( "Setup join timeout for " + message
.getHeader( Message.CONVERSATION_ID ) );
context.setTimeout( "join", timeout( ClusterMessage.joiningTimeout, message,
new URI( message.getHeader( Message.FROM ) ) ) );
return joining;
}
else
{
// Already in (probably due to crash of this server previously), go to entered state
context.joined();
outgoing.offer( internal( ClusterMessage.joinResponse, context.getConfiguration() ) );
return entered;
}
}
case configurationTimeout:
{
if ( context.hasJoinBeenDenied() )
{
outgoing.offer( internal( ClusterMessage.joinFailure,
new ClusterEntryDeniedException( context.getMyId(),
context.getJoinDeniedConfigurationResponseState() ) ) );
return start;
}
ClusterMessage.ConfigurationTimeoutState state = message.getPayload();
if ( state.getRemainingPings() > 0 )
{
// Send out requests again
for ( URI potentialClusterInstanceUri : context.getJoiningInstances() )
{
outgoing.offer( to( ClusterMessage.configurationRequest,
potentialClusterInstanceUri,
new ClusterMessage.ConfigurationRequestState(
context.getMyId(), context.boundAt() ) ) );
}
context.setTimeout( "join",
timeout( ClusterMessage.configurationTimeout, message,
new ClusterMessage.ConfigurationTimeoutState(
state.getRemainingPings() - 1 ) ) );
}
else
{
/*
* No configuration responses. Check if we picked up any other instances' requests during this phase.
* If we did, or we are the only instance in the configuration we can go ahead and try to start the
* cluster.
*/
if ( !discoveredInstances.isEmpty() || count( context.getJoiningInstances() ) == 1 )
{
Collections.sort( discoveredInstances );
/*
* The assumption here is that the lowest in the list of discovered instances
* will create the cluster. Keep in mind that this is run on all instances so
* everyone will pick the same one.
* If the one picked up is configured to not init a cluster then the timeout
* set in else{} will take care of that.
* We also start the cluster if we are the only configured instance. joiningInstances
* does not contain us, ever.
*/
ClusterMessage.ConfigurationRequestState ourRequestState =
new ClusterMessage.ConfigurationRequestState(context.getMyId(), context.boundAt());
// No one to join with
boolean imAlone =
count(context.getJoiningInstances()) == 1
&& discoveredInstances.contains(ourRequestState)
&& discoveredInstances.size() == 1;
// Enough instances discovered (half or more - i don't count myself here)
boolean haveDiscoveredMajority =
discoveredInstances.size() > count(context.getJoiningInstances()) / 2;
// I am supposed to create the cluster (i am before the first in the list of the discovered instances)
boolean wantToStartCluster =
!discoveredInstances.isEmpty()
&& discoveredInstances.get( 0 ).getJoiningId().compareTo(context.getMyId() ) >= 0;
if ( imAlone || haveDiscoveredMajority && wantToStartCluster )
{
discoveredInstances.clear();
// I'm supposed to create the cluster - fail the join
outgoing.offer( internal( ClusterMessage.joinFailure,
new TimeoutException(
"Join failed, timeout waiting for configuration" ) ) );
return start;
}
else
{
discoveredInstances.clear();
// Someone else is supposed to create the cluster - restart the join discovery
for ( URI potentialClusterInstanceUri : context.getJoiningInstances() )
{
outgoing.offer( to( ClusterMessage.configurationRequest,
potentialClusterInstanceUri,
new ClusterMessage.ConfigurationRequestState( context.getMyId(),
context.boundAt() ) ) );
}
context.setTimeout( "discovery",
timeout( ClusterMessage.configurationTimeout, message,
new ClusterMessage.ConfigurationTimeoutState( 4 ) ) );
}
}
else
{
context.setTimeout( "join",
timeout( ClusterMessage.configurationTimeout, message,
new ClusterMessage.ConfigurationTimeoutState( 4 ) ) );
}
}
return this;
}
case configurationRequest:
{
// We're listening for existing clusters, but if all instances start up at the same time
// and look for each other, this allows us to pick that up
ClusterMessage.ConfigurationRequestState configurationRequested = message.getPayload();
configurationRequested = new ClusterMessage.ConfigurationRequestState( configurationRequested.getJoiningId(), URI.create(message.getHeader( Message.FROM ) ));
if ( !discoveredInstances.contains( configurationRequested ))
{
for ( ClusterMessage.ConfigurationRequestState discoveredInstance :
discoveredInstances )
{
if ( discoveredInstance.getJoiningId().equals( configurationRequested.getJoiningId() ) )
{
// we are done
StringBuffer errorMessage = new StringBuffer( "Failed to join cluster because I saw two instances with the same ServerId" );
errorMessage.append( "One is " ).append( discoveredInstance.getJoiningId() );
errorMessage.append( " The other is " ).append( configurationRequested );
outgoing.offer( internal( ClusterMessage.joinFailure,
new IllegalStateException( errorMessage.toString() ) ) );
return start;
}
}
discoveredInstances.add( configurationRequested );
}
break;
}
case joinDenied:
{
// outgoing.offer( internal( ClusterMessage.joinFailure,
// new ClusterEntryDeniedException( context.me, context.configuration ) ) );
// return start;
context.joinDenied( (ClusterMessage.ConfigurationResponseState) message.getPayload() );
return this;
}
}
return this;
}
},
joining
{
@Override
public State<?, ?> handle( ClusterContext context,
Message<ClusterMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case configurationChanged:
{
ClusterMessage.ConfigurationChangeState state = message.getPayload();
if ( context.getMyId().equals( state.getJoin() ) )
{
context.cancelTimeout( "join" );
context.joined();
outgoing.offer( message.copyHeadersTo( internal( ClusterMessage.joinResponse, context.getConfiguration() ) ) );
return entered;
}
else
{
state.apply( context );
return this;
}
}
case joiningTimeout:
{
context.getLogger( ClusterState.class ).info( "Join timeout for " + message.getHeader(
Message.CONVERSATION_ID ) );
if ( context.hasJoinBeenDenied() )
{
outgoing.offer( internal( ClusterMessage.joinFailure,
new ClusterEntryDeniedException( context.getMyId(),
context.getJoinDeniedConfigurationResponseState() ) ) );
return start;
}
// Go back to requesting configurations from potential members
for ( URI potentialClusterInstanceUri : context.getJoiningInstances() )
{
outgoing.offer( to( ClusterMessage.configurationRequest,
potentialClusterInstanceUri,
new ClusterMessage.ConfigurationRequestState( context.getMyId(), context.boundAt() ) ) );
}
context.setTimeout( "discovery",
timeout( ClusterMessage.configurationTimeout, message,
new ClusterMessage.ConfigurationTimeoutState( 4 ) ) );
return discovery;
}
case joinFailure:
{
// This causes an exception from the join() method
return start;
}
}
return this;
}
},
entered
{
@Override
public State<?, ?> handle( ClusterContext context, Message<ClusterMessage> message,
MessageHolder outgoing ) throws Throwable
{
switch ( message.getMessageType() )
{
case addClusterListener:
{
context.addClusterListener( message.<ClusterListener>getPayload() );
break;
}
case removeClusterListener:
{
context.removeClusterListener( message.<ClusterListener>getPayload() );
break;
}
case configurationRequest:
{
ClusterMessage.ConfigurationRequestState request = message.getPayload();
request = new ClusterMessage.ConfigurationRequestState( request.getJoiningId(), URI.create(message.getHeader( Message.FROM ) ));
InstanceId joiningId = request.getJoiningId();
URI joiningUri = request.getJoiningUri();
boolean isInCluster = context.getMembers().containsKey( joiningId );
boolean isCurrentlyAlive = context.isCurrentlyAlive(joiningId);
boolean messageComesFromSameHost = request.getJoiningId().equals( context.getMyId() );
boolean otherInstanceJoiningWithSameId = context.isInstanceJoiningFromDifferentUri(
joiningId, joiningUri );
boolean isFromSameURIAsTheOneWeAlreadyKnow = context.getUriForId( joiningId ) != null &&
context.getUriForId( joiningId ).equals( joiningUri );
boolean somethingIsWrong =
( isInCluster && !messageComesFromSameHost && isCurrentlyAlive && !isFromSameURIAsTheOneWeAlreadyKnow )
|| otherInstanceJoiningWithSameId ;
if ( somethingIsWrong )
{
if(otherInstanceJoiningWithSameId)
{
context.getLogger( ClusterState.class ).info( "Denying entry to instance " + joiningId + " because another instance is currently joining with the same id.");
}
else
{
context.getLogger( ClusterState.class ).info( "Denying entry to instance " + joiningId + " because that instance is already in the cluster.");
}
outgoing.offer( message.copyHeadersTo( respond( ClusterMessage.joinDenied, message,
new ClusterMessage.ConfigurationResponseState( context.getConfiguration()
.getRoles(), context.getConfiguration().getMembers(),
new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( context.getLastDeliveredInstanceId() ),
context.getConfiguration().getName() ) ) ) );
}
else
{
context.instanceIsJoining(joiningId, joiningUri );
outgoing.offer( message.copyHeadersTo( respond( ClusterMessage.configurationResponse, message,
new ClusterMessage.ConfigurationResponseState( context.getConfiguration()
.getRoles(), context.getConfiguration().getMembers(),
new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId( context.getLastDeliveredInstanceId() ),
context.getConfiguration().getName() ) ) ) );
}
break;
}
case configurationChanged:
{
ClusterMessage.ConfigurationChangeState state = message.getPayload();
state.apply( context );
break;
}
case leave:
{
List<URI> nodeList = new ArrayList<URI>( context.getConfiguration().getMemberURIs() );
if ( nodeList.size() == 1 )
{
context.getLogger( ClusterState.class ).info( "Shutting down cluster: " + context
.getConfiguration().getName() );
context.left();
return start;
}
else
{
context.getLogger( ClusterState.class ).info( "Leaving:" + nodeList );
ClusterMessage.ConfigurationChangeState newState = new ClusterMessage
.ConfigurationChangeState();
newState.leave( context.getMyId() );
outgoing.offer( internal( AtomicBroadcastMessage.broadcast, newState ) );
context.setTimeout( "leave", timeout( ClusterMessage.leaveTimedout,
message ) );
return leaving;
}
}
}
return this;
}
},
leaving
{
@Override
public State<?, ?> handle( ClusterContext context,
Message<ClusterMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case configurationChanged:
{
ClusterMessage.ConfigurationChangeState state = message.getPayload();
if ( state.isLeaving( context.getMyId() ) )
{
context.cancelTimeout( "leave" );
context.left();
return start;
}
else
{
state.apply( context );
return leaving;
}
}
case leaveTimedout:
{
context.getLogger( ClusterState.class ).warn( "Failed to leave. Cluster may consider this" +
" instance still a member" );
context.left();
return start;
}
}
return this;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_cluster_ClusterState.java
|
5,970
|
public interface Election
{
void demote( InstanceId node );
/**
* Asks an election to be performed for all currently known roles, regardless of someone holding that role
* currently. It is allowed for the same instance to be reelected.
*/
void performRoleElections();
void promote( InstanceId node, String role );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_election_Election.java
|
5,971
|
public interface ElectionContext
extends TimeoutsContext, LoggingContext, ConfigurationContext
{
void created();
List<ElectionRole> getPossibleRoles();
/*
* Removes all roles from the provided node. This is expected to be the first call when receiving a demote
* message for a node, since it is the way to ensure that election will happen for each role that node had
*/
void nodeFailed( InstanceId node );
Iterable<String> getRoles( InstanceId server );
void unelect( String roleName );
boolean isElectionProcessInProgress( String role );
void startDemotionProcess( String role, final InstanceId demoteNode );
void startElectionProcess( String role );
void startPromotionProcess( String role, final InstanceId promoteNode );
void voted( String role, InstanceId suggestedNode, Comparable<Object> suggestionCredentials );
InstanceId getElectionWinner( String role );
Comparable<Object> getCredentialsForRole( String role );
int getVoteCount( String role );
int getNeededVoteCount();
void cancelElection( String role );
Iterable<String> getRolesRequiringElection();
boolean electionOk();
boolean isInCluster();
Iterable<InstanceId> getAlive();
boolean isElector();
boolean isFailed( InstanceId key );
InstanceId getElected( String roleName );
boolean hasCurrentlyElectedVoted( String role, InstanceId currentElected );
Set<InstanceId> getFailed();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_election_ElectionContext.java
|
5,972
|
public interface ElectionCredentials extends Comparable
{
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_election_ElectionCredentials.java
|
5,973
|
public interface ElectionCredentialsProvider
{
ElectionCredentials getCredentials( String role );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_election_ElectionCredentialsProvider.java
|
5,974
|
public enum ElectionMessage
implements MessageType
{
created,join,leave,
demote, performRoleElections, promote, vote, electionTimeout, voted;
public static class VotedData
implements Serializable
{
private final String role;
private final InstanceId instanceId;
private final Comparable<Object> voteCredentials;
public VotedData( String role, InstanceId instanceId, Comparable<Object> voteCredentials )
{
this.role = role;
this.instanceId = instanceId;
this.voteCredentials = voteCredentials;
}
public String getRole()
{
return role;
}
public InstanceId getInstanceId()
{
return instanceId;
}
public Comparable<Object> getVoteCredentials()
{
return voteCredentials;
}
@Override
public String toString()
{
return getClass().getSimpleName() + "[role:" + role + ", instance:" + instanceId + ", credentials:" +
voteCredentials + "]";
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_election_ElectionMessage.java
|
5,975
|
public enum ElectionState
implements State<ElectionContext, ElectionMessage>
{
start
{
@Override
public State<?, ?> handle( ElectionContext context,
Message<ElectionMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case created:
{
context.created();
return election;
}
case join:
{
return election;
}
}
return this;
}
},
election
{
@Override
public State<?, ?> handle( ElectionContext context,
Message<ElectionMessage> message,
MessageHolder outgoing
)
throws Throwable
{
StringLogger logger = context.getLogger( ElectionState.class );
switch ( message.getMessageType() )
{
case demote:
{
if ( !context.electionOk() )
{
logger.warn( "Context says election is not OK to proceed. " +
"Failed instances are: " +
context.getFailed() +
", cluster members are: " +
context.getMembers() );
break;
}
InstanceId demoteNode = message.getPayload();
// TODO Could perhaps be done better?
context.nodeFailed( demoteNode );
if ( context.isInCluster() )
{
// Only the first alive server should try elections. Everyone else waits
List<InstanceId> aliveInstances = Iterables.toList(context.getAlive());
Collections.sort( aliveInstances );
boolean isElector = aliveInstances.indexOf( context.getMyId() ) == 0;
if ( isElector )
{
logger.debug( "I (" + context.getMyId() + ") am the elector, " +
"executing the election" );
// Start election process for all roles that are currently unassigned
Iterable<String> rolesRequiringElection = context.getRolesRequiringElection();
for ( String role : rolesRequiringElection )
{
if ( !context.isElectionProcessInProgress( role ) )
{
logger.debug(
"Starting election process for role " + role );
context.startDemotionProcess( role, demoteNode );
// Allow other live nodes to vote which one should take over
for ( Map.Entry<InstanceId, URI> server : context.getMembers().entrySet() )
{
if ( !context.getFailed().contains( server.getKey() ) )
{
// This is a candidate - allow it to vote itself for promotion
outgoing.offer( Message.to( ElectionMessage.vote, server.getValue(), role ) );
}
}
context.setTimeout( "election-" + role,
Message.timeout( ElectionMessage.electionTimeout, message,
new ElectionTimeoutData( role, message ) ) );
}
else
{
logger.debug(
"Election already in progress for role " + role );
}
}
}
}
break;
}
case performRoleElections:
{
if ( !context.electionOk() )
{
break;
}
if ( context.isInCluster() )
{
boolean isElector = context.isElector();
if ( isElector )
{
// Start election process for all roles
Iterable<ElectionRole> rolesRequiringElection = context.getPossibleRoles();
for ( ElectionRole role : rolesRequiringElection )
{
String roleName = role.getName();
if ( !context.isElectionProcessInProgress( roleName ) )
{
context.getLogger(ElectionState.class).debug(
"Starting election process for role " + roleName );
context.startElectionProcess( roleName );
boolean sentSome = false;
// Allow other live nodes to vote which one should take over
for ( Map.Entry<InstanceId, URI> server : context.getMembers().entrySet() )
{
/*
* Skip dead nodes and the current role holder. Dead nodes are not
* candidates anyway and the current role holder will be asked last,
* after everyone else has cast votes.
*/
if ( !context.isFailed( server.getKey() ) &&
!server.getKey().equals( context.getElected( roleName ) ) )
{
// This is a candidate - allow it to vote itself for promotion
outgoing.offer( Message.to( ElectionMessage.vote, server.getValue(), roleName ) );
sentSome = true;
}
}
if ( !sentSome )
{
/*
* If we didn't send any messages, we are the only non-failed cluster
* member and probably (not necessarily) hold the role, though that
* doesn't matter. So we ask ourselves to vote, if we didn't above.
* In this case, no timeout is required, because no messages are
* expected. If we are indeed the role holder, then we'll cast our
* vote as a response to this message, which will complete the election.
*/
outgoing.offer( Message.internal( ElectionMessage.vote, roleName ) );
}
else
{
context.setTimeout( "election-" + roleName,
Message.timeout( ElectionMessage.electionTimeout, message,
new ElectionTimeoutData( roleName, message ) ) );
}
}
else
{
logger.debug(
"Election already in progress for role " + roleName );
}
}
}
else
{
List<InstanceId> aliveInstances = Iterables.toList( context.getAlive() );
Collections.sort( aliveInstances );
outgoing.offer( message.setHeader( Message.TO,
context.getUriForId( first( aliveInstances ) ).toString() ) );
}
}
break;
}
case promote:
{
Object[] args = message.getPayload();
InstanceId promoteNode = (InstanceId) args[0];
String role = (String) args[1];
// Start election process for coordinator role
if ( context.isInCluster() && !context.isElectionProcessInProgress( role ) )
{
context.startPromotionProcess( role, promoteNode );
// Allow other live nodes to vote which one should take over
for ( Map.Entry<InstanceId, URI> server : context.getMembers().entrySet() )
{
if ( !context.getFailed().contains( server.getKey() ) )
{
// This is a candidate - allow it to vote itself for promotion
outgoing.offer( Message.to( ElectionMessage.vote, server.getValue(), role ) );
}
}
context.setTimeout( "election-" + role, Message.timeout( ElectionMessage
.electionTimeout, message, new ElectionTimeoutData( role, message ) ) );
}
break;
}
case vote:
{
String role = message.getPayload();
outgoing.offer( Message.respond( ElectionMessage.voted, message,
new ElectionMessage.VotedData( role, context.getMyId(),
context.getCredentialsForRole( role ) ) ) );
break;
}
case voted:
{
ElectionMessage.VotedData data = message.getPayload();
context.voted( data.getRole(), data.getInstanceId(), data.getVoteCredentials() );
String voter = message.hasHeader( Message.FROM ) ? message.getHeader( Message.FROM ) : "I";
logger.debug( voter + " voted " + data );
/*
* This is the URI of the current role holder and, yes, it could very well be null. However
* we don't really care. If it is null then the election would not have sent one vote
* request less than needed (i.e. ask the master last) since, well, it doesn't exist. So
* the immediate effect is that the else (which checks for null) will never be called.
*/
InstanceId currentElected = context.getElected( data.getRole() );
if ( context.getVoteCount( data.getRole() ) == context.getNeededVoteCount() )
{
// We have all votes now
InstanceId winner = context.getElectionWinner( data.getRole() );
if ( winner != null )
{
logger.debug( "Elected " + winner + " as " + data.getRole() );
// Broadcast this
ClusterMessage.ConfigurationChangeState configurationChangeState = new
ClusterMessage.ConfigurationChangeState();
configurationChangeState.elected( data.getRole(), winner );
outgoing.offer( Message.internal( ProposerMessage.propose,
configurationChangeState ) );
}
else
{
logger.warn( "Election could not pick a winner" );
if ( currentElected != null )
{
// Someone had the role and doesn't anymore. Broadcast this
ClusterMessage.ConfigurationChangeState configurationChangeState = new
ClusterMessage.ConfigurationChangeState();
configurationChangeState.unelected( data.getRole(), currentElected );
outgoing.offer( Message.internal( ProposerMessage.propose,
configurationChangeState ) );
}
}
context.cancelTimeout( "election-" + data.getRole() );
}
else if ( context.getVoteCount( data.getRole() ) == context.getNeededVoteCount() - 1 &&
currentElected != null && !context.hasCurrentlyElectedVoted(data.getRole(), currentElected))
{
// Missing one vote, the one from the current role holder
outgoing.offer( Message.to( ElectionMessage.vote,
context.getUriForId( currentElected ),
data.getRole() ) );
}
break;
}
case electionTimeout:
{
// Election failed - try again
ElectionTimeoutData electionTimeoutData = message.getPayload();
logger.warn( String.format(
"Election timed out for '%s'- trying again", electionTimeoutData.getRole() ) );
context.cancelElection( electionTimeoutData.getRole() );
outgoing.offer( electionTimeoutData.getMessage() );
break;
}
case leave:
{
return start;
}
}
return this;
}
};
private static class ElectionTimeoutData
{
private final String role;
private final Message message;
private ElectionTimeoutData( String role, Message message )
{
this.role = role;
this.message = message;
}
public String getRole()
{
return role;
}
public Message getMessage()
{
return message;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_election_ElectionState.java
|
5,976
|
public interface Heartbeat
{
void addHeartbeatListener( HeartbeatListener listener );
void removeHeartbeatListener( HeartbeatListener listener );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_heartbeat_Heartbeat.java
|
5,977
|
public interface HeartbeatContext
extends TimeoutsContext, ConfigurationContext, LoggingContext
{
void started();
/**
* @return True iff the node was suspected
*/
boolean alive( final InstanceId node );
void suspect( final InstanceId node );
void suspicions( InstanceId from, Set<InstanceId> suspicions );
Set<InstanceId> getFailed();
Iterable<InstanceId> getAlive();
void addHeartbeatListener( HeartbeatListener listener );
void removeHeartbeatListener( HeartbeatListener listener );
void serverLeftCluster( InstanceId node );
boolean isFailed( InstanceId node );
List<InstanceId> getSuspicionsOf( InstanceId server );
Set<InstanceId> getSuspicionsFor( InstanceId uri );
Iterable<InstanceId> getOtherInstances();
long getLastKnownLearnedInstanceInCluster();
long getLastLearnedInstanceId();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_heartbeat_HeartbeatContext.java
|
5,978
|
public interface HeartbeatListener
{
void failed( InstanceId server );
void alive( InstanceId server );
public static class Adapter implements HeartbeatListener
{
@Override
public void failed( InstanceId server )
{
}
@Override
public void alive( InstanceId server )
{
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_heartbeat_HeartbeatListener.java
|
5,979
|
public enum HeartbeatMessage
implements MessageType
{
// Heartbeat API messages
addHeartbeatListener, removeHeartbeatListener,
// Protocol messages
join, leave,
i_am_alive, timed_out, sendHeartbeat, reset_send_heartbeat, suspicions;
public static class IAmAliveState
implements Serializable
{
private final InstanceId server;
public IAmAliveState( InstanceId server )
{
this.server = server;
}
public InstanceId getServer()
{
return server;
}
@Override
public String toString()
{
return "i_am_alive[" + server + "]";
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
IAmAliveState that = (IAmAliveState) o;
if ( server != null ? !server.equals( that.server ) : that.server != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return server != null ? server.hashCode() : 0;
}
}
public static class SuspicionsState
implements Serializable
{
private static final long serialVersionUID = 3152836192116904427L;
private Set<InstanceId> suspicions;
public SuspicionsState( Set<InstanceId> suspicions )
{
this.suspicions = suspicions;
}
public Set<InstanceId> getSuspicions()
{
return suspicions;
}
@Override
public String toString()
{
return "Suspicions:"+suspicions;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
SuspicionsState that = (SuspicionsState) o;
if ( suspicions != null ? !suspicions.equals( that.suspicions ) : that.suspicions != null )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return suspicions != null ? suspicions.hashCode() : 0;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_heartbeat_HeartbeatMessage.java
|
5,980
|
public enum HeartbeatState
implements State<HeartbeatContext, HeartbeatMessage>
{
start
{
@Override
public HeartbeatState handle( HeartbeatContext context,
Message<HeartbeatMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case addHeartbeatListener:
{
context.addHeartbeatListener( (HeartbeatListener) message.getPayload() );
break;
}
case removeHeartbeatListener:
{
context.removeHeartbeatListener( (HeartbeatListener) message.getPayload() );
break;
}
case join:
{
for ( InstanceId instanceId : context.getOtherInstances() )
{
// Setup heartbeat timeouts for the other instance
context.setTimeout(
HeartbeatMessage.i_am_alive + "-" + instanceId,
timeout( HeartbeatMessage.timed_out, message, instanceId ) );
// Send first heartbeat immediately
outgoing.offer( timeout( HeartbeatMessage.sendHeartbeat, message, instanceId) );
}
return heartbeat;
}
}
return this;
}
},
heartbeat
{
@Override
public HeartbeatState handle( HeartbeatContext context,
Message<HeartbeatMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case i_am_alive:
{
HeartbeatMessage.IAmAliveState state = message.getPayload();
if (context.isMe( state.getServer() ) )
{
break;
}
context.getLogger( HeartbeatState.class ).debug( "Received " + state );
if ( state.getServer() == null )
{
break;
}
if ( context.alive( state.getServer() ) )
{
// Send suspicions messages to all non-failed servers
for ( InstanceId aliveServer : context.getAlive() )
{
if ( !aliveServer.equals( context.getMyId() ) )
{
URI aliveServerUri =
context.getUriForId( aliveServer );
outgoing.offer( Message.to( HeartbeatMessage.suspicions, aliveServerUri,
new HeartbeatMessage.SuspicionsState( context.getSuspicionsFor( context.getMyId() ) ) ) );
}
}
}
context.cancelTimeout( HeartbeatMessage.i_am_alive + "-" +
state.getServer() );
context.setTimeout( HeartbeatMessage.i_am_alive + "-" +
state.getServer(), timeout( HeartbeatMessage.timed_out, message, state
.getServer() ) );
// Check if this server knows something that we don't
if ( message.hasHeader( "last-learned" ) )
{
long lastLearned = Long.parseLong( message.getHeader( "last-learned" ) );
if ( lastLearned > context.getLastKnownLearnedInstanceInCluster() )
{
outgoing.offer( internal( LearnerMessage.catchUp, lastLearned ) );
}
}
break;
}
case timed_out:
{
InstanceId server = message.getPayload();
context.getLogger( HeartbeatState.class )
.debug( "Received timed out for server " + server );
// Check if this node is no longer a part of the cluster
if ( context.getMembers().containsKey( server ) )
{
context.suspect( server );
context.setTimeout( HeartbeatMessage.i_am_alive + "-" +
server, timeout( HeartbeatMessage.timed_out, message, server ) );
// Send suspicions messages to all non-failed servers
for ( InstanceId aliveServer : context.getAlive() )
{
if ( !aliveServer.equals( context.getMyId() ) )
{
URI sendTo = context.getUriForId(
aliveServer );
outgoing.offer( Message.to( HeartbeatMessage.suspicions, sendTo,
new HeartbeatMessage.SuspicionsState( context.getSuspicionsFor(
context.getMyId() ) ) ) );
}
}
}
else
{
// If no longer part of cluster, then don't bother
context.serverLeftCluster( server );
}
break;
}
case sendHeartbeat:
{
InstanceId to = message.getPayload();
if (!context.isMe( to ) )
{
// Check if this node is no longer a part of the cluster
if ( context.getMembers().containsKey( to ) )
{
URI toSendTo = context.getUriForId( to );
// Send heartbeat message to given server
outgoing.offer( to( HeartbeatMessage.i_am_alive, toSendTo,
new HeartbeatMessage.IAmAliveState(
context.getMyId() ) )
.setHeader( "last-learned",
context.getLastLearnedInstanceId() + "" ) );
// Set new timeout to send heartbeat to this host
context.setTimeout(
HeartbeatMessage.sendHeartbeat + "-" + to,
timeout( HeartbeatMessage.sendHeartbeat, message, to ) );
}
}
break;
}
case reset_send_heartbeat:
{
InstanceId to = message.getPayload();
if ( !context.isMe( to ) )
{
String timeoutName = HeartbeatMessage.sendHeartbeat + "-" + to;
context.cancelTimeout( timeoutName );
context.setTimeout( timeoutName, Message.timeout(
HeartbeatMessage.sendHeartbeat, message, to ) );
}
break;
}
case suspicions:
{
HeartbeatMessage.SuspicionsState suspicions = message.getPayload();
context.getLogger( HeartbeatState.class )
.debug( "Received suspicions as " + suspicions );
URI from = new URI( message.getHeader( Message.FROM ) );
InstanceId fromId = context.getIdForUri( from );
/*
* Remove ourselves from the suspicions received - we just received a message,
* it's not normal to be considered failed. Whatever it was, it was transient and now it has
* passed.
*/
suspicions.getSuspicions().remove( context.getMyId() );
context.suspicions( fromId, suspicions.getSuspicions() );
break;
}
case leave:
{
context.getLogger( HeartbeatState.class ).debug( "Received leave" );
return start;
}
case addHeartbeatListener:
{
context.addHeartbeatListener( (HeartbeatListener) message.getPayload() );
break;
}
case removeHeartbeatListener:
{
context.removeHeartbeatListener( (HeartbeatListener) message.getPayload() );
break;
}
}
return this;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_heartbeat_HeartbeatState.java
|
5,981
|
public interface OmegaListener
{
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_omega_OmegaListener.java
|
5,982
|
public enum OmegaMessage implements MessageType
{
/*
* Boring administrative messages
*/
add_listener, remove_listener, start,
/*
* The required timeouts
*/
refresh_timeout, round_trip_timeout, read_timeout,
/*
* The refresh request, where we send our state to
* f other processes
*/
refresh,
/*
* The message to respond with on refresh requests
*/
refresh_ack,
/*
* The collect request, sent to gather up the states of
* n-f other machines
*/
collect,
/*
* The response to a collect request, sending
* back the registry
*/
status;
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_omega_OmegaMessage.java
|
5,983
|
public enum OmegaState implements State<OmegaContext, OmegaMessage>
{
start
{
@Override
public OmegaState handle( OmegaContext context, Message<OmegaMessage> message,
MessageHolder outgoing ) throws Throwable
{
switch ( message.getMessageType() )
{
case add_listener:
context.addListener( (OmegaListener) message.getPayload() );
break;
case remove_listener:
context.removeListener( (OmegaListener) message.getPayload() );
break;
case start:
context.startTimers();
return omega;
}
return this;
}
},
omega
{
@Override
public State<?, ?> handle( OmegaContext context, Message<OmegaMessage> message,
MessageHolder outgoing ) throws Throwable
{
switch ( message.getMessageType() )
{
case refresh_timeout:
{
int refreshRoundId = context.startRefreshRound();
for ( URI server : context.getServers() )
{
outgoing.offer( Message.to( OmegaMessage.refresh, server,
RefreshPayload.fromState( context.getMyState(),
refreshRoundId ) ) );
}
}
break;
case refresh:
{
org.neo4j.cluster.protocol.omega.state.State state = RefreshPayload.toState(
(RefreshPayload) message.getPayload() ).other();
URI from = new URI( message.getHeader( Message.FROM ) );
org.neo4j.cluster.protocol.omega.state.State currentForThisHost = context.getRegistry().get( from );
if ( currentForThisHost == null || currentForThisHost.compareTo( state ) < 0 )
{
context.getRegistry().put( from, state );
}
outgoing.offer( Message.to(
OmegaMessage.refresh_ack,
from,
RefreshAckPayload.forRefresh( (RefreshPayload) message
.getPayload() ) ) );
}
break;
case refresh_ack:
{
RefreshAckPayload ack = message.getPayload();
// TODO deal with duplicate/corrupted messages here perhaps?
int refreshRound = ack.round;
context.ackReceived( refreshRound );
if ( context.getAckCount( refreshRound ) > context.getClusterNodeCount() / 2 )
{
context.getMyState().increaseFreshness();
context.roundDone( refreshRound );
}
}
break;
case round_trip_timeout:
{
context.getMyView().setExpired( true );
context.getMyState().getEpochNum().increaseSerialNum();
}
break;
case read_timeout:
{
int collectRound = context.startCollectionRound();
for ( URI server : context.getServers() )
{
outgoing.offer( Message.to(
OmegaMessage.collect,
server,
new CollectPayload( collectRound ) ) );
}
}
break;
case collect:
{
CollectPayload payload = message.getPayload();
URI from = new URI( message.getHeader( Message.FROM ) );
int readNum = payload.getReadNum();
outgoing.offer( Message.to( OmegaMessage.status,
from,
CollectResponsePayload.fromRegistry( context.getRegistry(), readNum ) ) );
}
break;
case status:
{
CollectResponsePayload payload = message.getPayload();
URI from = new URI( message.getHeader( Message.FROM ) );
int readNum = payload.getReadNum();
context.responseReceivedForRound( readNum, from, CollectResponsePayload.fromPayload( payload ));
if ( context.getStatusResponsesForRound( readNum ) > context.getClusterNodeCount() / 2 )
{
context.collectionRoundDone( readNum );
}
}
break;
default:
throw new IllegalArgumentException( message.getMessageType() +" is unknown" );
}
return this;
}
};
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_omega_OmegaState.java
|
5,984
|
public interface Snapshot
{
void setSnapshotProvider(SnapshotProvider snapshotProvider);
void refreshSnapshot();
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_snapshot_Snapshot.java
|
5,985
|
public enum SnapshotMessage
implements MessageType
{
join, leave,
setSnapshotProvider,
refreshSnapshot,
sendSnapshot, snapshot;
// TODO This needs to be replaced with something that can handle bigger snapshots
public static class SnapshotState
implements Serializable
{
private long lastDeliveredInstanceId = -1;
transient SnapshotProvider provider;
private transient ObjectInputStreamFactory objectInputStreamFactory;
private transient ObjectOutputStreamFactory objectOutputStreamFactory;
transient byte[] buf;
public SnapshotState( long lastDeliveredInstanceId, SnapshotProvider provider,
ObjectInputStreamFactory objectInputStreamFactory,
ObjectOutputStreamFactory objectOutputStreamFactory )
{
this.lastDeliveredInstanceId = lastDeliveredInstanceId;
this.provider = provider;
if ( objectInputStreamFactory == null )
{
throw new RuntimeException( "objectInputStreamFactory was null" );
}
if ( objectOutputStreamFactory == null )
{
throw new RuntimeException( "objectOutputStreamFactory was null" );
}
this.objectInputStreamFactory = objectInputStreamFactory;
this.objectOutputStreamFactory = objectOutputStreamFactory;
}
public long getLastDeliveredInstanceId()
{
return lastDeliveredInstanceId;
}
public void setState( SnapshotProvider provider, ObjectInputStreamFactory objectInputStreamFactory )
throws IOException
{
ByteArrayInputStream bin = new ByteArrayInputStream( buf );
ObjectInputStream oin = objectInputStreamFactory.create( bin );
try
{
provider.setState( oin );
}
catch ( Throwable e )
{
e.printStackTrace();
}
finally
{
oin.close();
}
}
private void writeObject( java.io.ObjectOutputStream out )
throws IOException
{
out.defaultWriteObject();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = objectOutputStreamFactory.create( bout );
provider.getState( oout );
oout.close();
byte[] buf = bout.toByteArray();
out.writeInt( buf.length );
out.write( buf );
}
private void readObject( java.io.ObjectInputStream in )
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
buf = new byte[in.readInt()];
try
{
in.readFully( buf );
}
catch ( EOFException endOfFile )
{
// do nothing - the stream's ended but the message content got through ok.
}
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_snapshot_SnapshotMessage.java
|
5,986
|
public interface SnapshotProvider
{
void getState(ObjectOutputStream output)
throws IOException;
void setState(ObjectInputStream input)
throws IOException, ClassNotFoundException;
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_snapshot_SnapshotProvider.java
|
5,987
|
public enum SnapshotState
implements State<SnapshotContext, SnapshotMessage>
{
start
{
@Override
public State<?, ?> handle( SnapshotContext context,
Message<SnapshotMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case setSnapshotProvider:
{
SnapshotProvider snapshotProvider = message.getPayload();
context.setSnapshotProvider( snapshotProvider );
break;
}
case refreshSnapshot:
{
if ( context.getClusterContext().getConfiguration().getMembers().size() <= 1 ||
context.getSnapshotProvider() == null )
{
// we are the only instance or there are no snapshots
return start;
}
else
{
InstanceId coordinator = context.getClusterContext().getConfiguration().getElected(
ClusterConfiguration.COORDINATOR );
if ( coordinator != null )
{
// there is a coordinator - ask from that
outgoing.offer( Message.to( SnapshotMessage.sendSnapshot,
context.getClusterContext().getConfiguration().getUriForId(
coordinator ) ) );
return refreshing;
}
else
{
return start;
}
}
}
case join:
{
// go to ready state, if someone needs snapshots they should ask for it explicitly.
return ready;
}
}
return this;
}
},
refreshing
{
@Override
public State<?, ?> handle( SnapshotContext context,
Message<SnapshotMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case snapshot:
{
SnapshotMessage.SnapshotState state = message.getPayload();
// If we have already delivered everything that is rolled into this snapshot, ignore it
state.setState( context.getSnapshotProvider(), context.getClusterContext().getObjectInputStreamFactory() );
return ready;
}
}
return this;
}
},
ready
{
@Override
public State<?, ?> handle( SnapshotContext context,
Message<SnapshotMessage> message,
MessageHolder outgoing
)
throws Throwable
{
switch ( message.getMessageType() )
{
case refreshSnapshot:
{
if ( context.getClusterContext().getConfiguration().getMembers().size() <= 1 ||
context.getSnapshotProvider() == null )
{
// we are the only instance in the cluster or snapshots are not meaningful
return ready;
}
else
{
InstanceId coordinator = context.getClusterContext().getConfiguration().getElected(
ClusterConfiguration.COORDINATOR );
if ( coordinator != null && !coordinator.equals( context.getClusterContext().getMyId() ) )
{
// coordinator exists, ask for the snapshot
outgoing.offer( Message.to( SnapshotMessage.sendSnapshot,
context.getClusterContext().getConfiguration().getUriForId(
coordinator ) ) );
return refreshing;
}
else
{
// coordinator is unknown, can't do much
return ready;
}
}
}
case sendSnapshot:
{
outgoing.offer( Message.respond( SnapshotMessage.snapshot, message,
new SnapshotMessage.SnapshotState( context.getLearnerContext()
.getLastDeliveredInstanceId(), context.getSnapshotProvider(),
context.getClusterContext().getObjectInputStreamFactory(),
context.getClusterContext().getObjectOutputStreamFactory()) ) );
break;
}
case leave:
{
return start;
}
}
return this;
}
}
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_protocol_snapshot_SnapshotState.java
|
5,988
|
public interface State<CONTEXT, MESSAGETYPE extends MessageType>
{
/**
* Handle a message. The state can use context for state storage/retrieval and it will also act
* as a facade to the rest of the system. The MessageProcessor is used to trigger new messages.
* When the handling is done the state returns the next state of the state machine.
*
*
* @param context that contains state and methods to access other parts of the system
* @param message that needs to be handled
* @param outgoing processor for new messages created by the handling of this message
* @return the new state
* @throws Throwable
*/
public State<?, ?> handle( CONTEXT context, Message<MESSAGETYPE> message, MessageHolder outgoing ) throws
Throwable;
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_statemachine_State.java
|
5,989
|
public interface StateTransitionListener
{
void stateTransition(StateTransition transition);
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_statemachine_StateTransitionListener.java
|
5,990
|
public interface TimeoutStrategy
{
long timeoutFor( Message message );
void timeoutTriggered( Message timeoutMessage );
void timeoutCancelled( Message timeoutMessage );
void tick( long now );
}
| false
|
enterprise_cluster_src_main_java_org_neo4j_cluster_timeout_TimeoutStrategy.java
|
5,991
|
public interface ConnectionLostHandler
{
public static final ConnectionLostHandler NO_ACTION = new ConnectionLostHandler()
{
@Override
public void handle( Exception e )
{
}
};
void handle( Exception e );
}
| false
|
enterprise_com_src_main_java_org_neo4j_com_ConnectionLostHandler.java
|
5,992
|
public interface Deserializer<T>
{
T read( ChannelBuffer buffer, ByteBuffer temporaryBuffer ) throws IOException;
}
| false
|
enterprise_com_src_main_java_org_neo4j_com_Deserializer.java
|
5,993
|
public interface MadeUpCommunicationInterface
{
Response<Integer> multiply( int value1, int value2 );
Response<Void> fetchDataStream( MadeUpWriter writer, int dataSize );
Response<Void> sendDataStream( ReadableByteChannel data );
Response<Integer> throwException( String messageInException );
}
| false
|
enterprise_com_src_test_java_org_neo4j_com_MadeUpCommunicationInterface.java
|
5,994
|
static enum MadeUpRequestType implements RequestType<MadeUpCommunicationInterface>
{
MULTIPLY( new TargetCaller<MadeUpCommunicationInterface, Integer>()
{
@Override
public Response<Integer> call( MadeUpCommunicationInterface master,
RequestContext context, ChannelBuffer input, ChannelBuffer target )
{
int value1 = input.readInt();
int value2 = input.readInt();
return master.multiply( value1, value2 );
}
}, Protocol.INTEGER_SERIALIZER ),
FETCH_DATA_STREAM( new TargetCaller<MadeUpCommunicationInterface, Void>()
{
@Override
public Response<Void> call( MadeUpCommunicationInterface master,
RequestContext context, ChannelBuffer input, ChannelBuffer target )
{
int dataSize = input.readInt();
return master.fetchDataStream( new ToChannelBufferWriter( target ), dataSize );
}
}, Protocol.VOID_SERIALIZER ),
SEND_DATA_STREAM( new TargetCaller<MadeUpCommunicationInterface, Void>()
{
@Override
public Response<Void> call( MadeUpCommunicationInterface master,
RequestContext context, ChannelBuffer input, ChannelBuffer target )
{
BlockLogReader reader = new BlockLogReader( input );
try
{
Response<Void> response = master.sendDataStream( reader );
return response;
}
finally
{
try
{
reader.close();
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}
}
}, Protocol.VOID_SERIALIZER ),
THROW_EXCEPTION( new TargetCaller<MadeUpCommunicationInterface, Integer>()
{
@Override
public Response<Integer> call( MadeUpCommunicationInterface master,
RequestContext context, ChannelBuffer input, ChannelBuffer target )
{
return master.throwException( readString( input ) );
}
}, Protocol.VOID_SERIALIZER ),
CAUSE_READ_CONTEXT_EXCEPTION( new TargetCaller<MadeUpCommunicationInterface, Integer>()
{
@Override
public Response<Integer> call( MadeUpCommunicationInterface master,
RequestContext context, ChannelBuffer input, ChannelBuffer target )
{
throw new ThisShouldNotHappenError( "Jake", "Test should not reach this far, " +
"it should fail while reading the request context." );
}
}, Protocol.VOID_SERIALIZER );
private final TargetCaller masterCaller;
private final ObjectSerializer serializer;
MadeUpRequestType( TargetCaller masterCaller, ObjectSerializer serializer )
{
this.masterCaller = masterCaller;
this.serializer = serializer;
}
@Override
public TargetCaller getTargetCaller()
{
return this.masterCaller;
}
@Override
public ObjectSerializer getObjectSerializer()
{
return this.serializer;
}
@Override
public byte id()
{
return (byte) ordinal();
}
}
| false
|
enterprise_com_src_test_java_org_neo4j_com_MadeUpServer.java
|
5,995
|
public interface MadeUpWriter
{
void write( ReadableByteChannel data );
}
| false
|
enterprise_com_src_test_java_org_neo4j_com_MadeUpWriter.java
|
5,996
|
public interface MismatchingVersionHandler
{
public void versionMismatched( int expected, int received );
}
| false
|
enterprise_com_src_main_java_org_neo4j_com_MismatchingVersionHandler.java
|
5,997
|
public interface ObjectSerializer<T>
{
void write( T responseObject, ChannelBuffer result ) throws IOException;
}
| false
|
enterprise_com_src_main_java_org_neo4j_com_ObjectSerializer.java
|
5,998
|
public interface RequestType<M>
{
TargetCaller getTargetCaller();
ObjectSerializer getObjectSerializer();
byte id();
}
| false
|
enterprise_com_src_main_java_org_neo4j_com_RequestType.java
|
5,999
|
public interface CheckStrategy
{
public boolean shouldCheck();
public class TimeoutCheckStrategy implements CheckStrategy
{
private final long interval;
private long lastCheckTime;
private final Clock clock;
public TimeoutCheckStrategy( long interval, Clock clock )
{
this.interval = interval;
this.lastCheckTime = clock.currentTimeMillis();
this.clock = clock;
}
@Override
public boolean shouldCheck()
{
long currentTime = clock.currentTimeMillis();
if ( currentTime > lastCheckTime + interval )
{
lastCheckTime = currentTime;
return true;
}
return false;
}
}
}
| false
|
enterprise_com_src_main_java_org_neo4j_com_ResourcePool.java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.