Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the ChannelInterceptor concept since it potentially left a gap between connect() and adding the interceptor where messages could slip by without being intercepted. Instead the complete handshake pipeline is installed immediately from the ChannelInitializer and the NettyPipelineBuilder has been extended with functionality to cater for the message gating. The message gate is now a free-standing handler of its own and which does as little as possible to fulfil its role. Closing and flusing logic has been moved outside to the components which drive the handshake.
- Loading branch information
1 parent
f35ebb8
commit 2626f03
Showing
24 changed files
with
605 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...sal-clustering/src/main/java/org/neo4j/causalclustering/messaging/ChannelInterceptor.java
This file was deleted.
Oops, something went wrong.
86 changes: 0 additions & 86 deletions
86
...e/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/HandshakeGate.java
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
...ise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/MessageGate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.messaging; | ||
|
||
import io.netty.channel.ChannelDuplexHandler; | ||
import io.netty.channel.ChannelHandler; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import org.neo4j.causalclustering.protocol.handshake.GateEvent; | ||
|
||
/** | ||
* Gates messages and keeps them on a queue until the gate is either | ||
* opened successfully or closed forever. | ||
*/ | ||
@ChannelHandler.Sharable | ||
public class MessageGate extends ChannelDuplexHandler | ||
{ | ||
private final Predicate<Object> gated; | ||
|
||
private List<GatedWrite> pending = new ArrayList<>(); | ||
|
||
public MessageGate( Predicate<Object> gated ) | ||
{ | ||
this.gated = gated; | ||
} | ||
|
||
@Override | ||
public void userEventTriggered( ChannelHandlerContext ctx, Object evt ) throws Exception | ||
{ | ||
if ( evt instanceof GateEvent ) | ||
{ | ||
if ( GateEvent.getSuccess().equals( evt ) ) | ||
{ | ||
for ( GatedWrite write : pending ) | ||
{ | ||
ctx.write( write.msg, write.promise ); | ||
} | ||
|
||
ctx.channel().pipeline().remove( this ); | ||
} | ||
|
||
pending.clear(); | ||
pending = null; | ||
} | ||
else | ||
{ | ||
super.userEventTriggered( ctx, evt ); | ||
} | ||
} | ||
|
||
@Override | ||
public void write( ChannelHandlerContext ctx, Object msg, ChannelPromise promise ) throws Exception | ||
{ | ||
if ( !gated.test( msg ) ) | ||
{ | ||
ctx.write( msg, promise ); | ||
} | ||
else if ( pending != null ) | ||
{ | ||
pending.add( new GatedWrite( msg, promise ) ); | ||
} | ||
else | ||
{ | ||
promise.setFailure( new RuntimeException( "Gate failed and has been permanently closed." ) ); | ||
} | ||
} | ||
|
||
static class GatedWrite | ||
{ | ||
final Object msg; | ||
final ChannelPromise promise; | ||
|
||
GatedWrite( Object msg, ChannelPromise promise ) | ||
{ | ||
this.msg = msg; | ||
this.promise = promise; | ||
} | ||
} | ||
} |
Oops, something went wrong.