-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
SessionStateMachine.java
892 lines (799 loc) · 31.6 KB
/
SessionStateMachine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
/*
* Copyright (c) 2002-2016 "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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.bolt.v1.runtime.internal;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.neo4j.bolt.security.auth.Authentication;
import org.neo4j.bolt.security.auth.AuthenticationException;
import org.neo4j.bolt.security.auth.AuthenticationResult;
import org.neo4j.bolt.v1.runtime.Session;
import org.neo4j.bolt.v1.runtime.StatementMetadata;
import org.neo4j.bolt.v1.runtime.spi.RecordStream;
import org.neo4j.bolt.v1.runtime.spi.StatementRunner;
import org.neo4j.graphdb.security.AuthorizationViolationException;
import org.neo4j.kernel.GraphDatabaseQueryService;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.security.AccessMode;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.query.Neo4jTransactionalContext;
import org.neo4j.kernel.impl.query.QuerySession;
import org.neo4j.udc.UsageData;
import static java.lang.String.format;
import static org.neo4j.kernel.api.KernelTransaction.Type.explicit;
import static org.neo4j.kernel.api.KernelTransaction.Type.implicit;
import static org.neo4j.kernel.api.exceptions.Status.Security.CredentialsExpired;
/**
* State-machine based implementation of {@link Session}. With this approach,
* the discrete states a session can be in are explicit. Each state describes which actions from the context
* interface are legal given that particular state, and how those actions behave given the current state.
*/
public class SessionStateMachine implements Session, SessionState
{
/**
* The session state machine, this is the heart of how a session operates. This enumerates the various discrete
* states a session can be in, and describes how it behaves in those states.
*/
enum State
{
/**
* Before the session has been initialized.
*/
UNINITIALIZED
{
@Override
public State init( SessionStateMachine ctx, String clientName, Map<String,Object> authToken )
{
try
{
AuthenticationResult authResult = ctx.spi.authenticate( authToken );
ctx.accessMode = authResult.getAccessMode();
ctx.credentialsExpired = authResult.credentialsExpired();
ctx.result( authResult.credentialsExpired() );
ctx.spi.udcRegisterClient( clientName );
ctx.setQuerySourceFromClientNameAndPrincipal( clientName, authToken.get( Authentication.PRINCIPAL ) );
return IDLE;
}
catch ( AuthenticationException e )
{
return error( ctx, new Neo4jError( e.status(), e.getMessage(), e ) );
}
catch ( Throwable e )
{
return error( ctx, e );
}
}
@Override
protected State onNoImplementation( SessionStateMachine ctx, String command )
{
ctx.error( new Neo4jError( Status.Request.Invalid, "No operations allowed until you send an " +
"INIT message." ) );
return halt( ctx );
}
},
/**
* No open transaction, no open result.
*/
IDLE
{
@Override
public State beginTransaction( SessionStateMachine ctx )
{
assert ctx.currentTransaction == null;
ctx.currentTransaction = ctx.spi.beginTransaction( explicit, ctx.accessMode );
return IN_TRANSACTION;
}
@Override
public State runStatement( SessionStateMachine ctx, String statement, Map<String,Object> params )
{
try
{
ctx.currentResult = ctx.spi.run( ctx, statement, params );
ctx.result( ctx.currentStatementMetadata );
//if the call to run failed we must remain in state ERROR
if ( ctx.state == ERROR )
{
return ERROR;
}
else
{
return STREAM_OPEN;
}
}
catch ( Throwable e )
{
return error( ctx, e );
}
}
@Override
public State beginImplicitTransaction( SessionStateMachine ctx )
{
assert ctx.currentTransaction == null;
// NOTE: If we move away from doing implicit transactions this
// way, we need a different way to kill statements running in implicit
// transactions, because we do that by calling #terminate() on this tx.
ctx.currentTransaction = ctx.spi.beginTransaction( implicit, ctx.accessMode );
return IN_TRANSACTION;
}
@Override
public State reset( SessionStateMachine ctx )
{
return IDLE;
}
@Override
public State rollbackTransaction( SessionStateMachine ctx )
{
return error( ctx, new Neo4jError( Status.Request.Invalid,
"rollback cannot be done when there is no open transaction in the session." ) );
}
},
/**
* Open transaction, no open stream
* <p>
* This is when the client has explicitly requested a transaction to be opened.
*/
IN_TRANSACTION
{
@Override
public State runStatement( SessionStateMachine ctx, String statement, Map<String,Object> params )
{
return IDLE.runStatement( ctx, statement, params );
}
@Override
public State commitTransaction( SessionStateMachine ctx )
{
try
{
KernelTransaction tx = ctx.currentTransaction;
ctx.currentTransaction = null;
tx.success();
tx.close();
}
catch ( Throwable e )
{
return error( ctx, e );
}
finally
{
ctx.currentTransaction = null;
}
return IDLE;
}
@Override
public State rollbackTransaction( SessionStateMachine ctx )
{
try
{
KernelTransaction tx = ctx.currentTransaction;
ctx.currentTransaction = null;
tx.failure();
tx.close();
return IDLE;
}
catch ( Throwable e )
{
return error( ctx, e );
}
}
@Override
public State reset( SessionStateMachine ctx )
{
return rollbackTransaction( ctx );
}
},
/**
* A result stream is ready for consumption, there may or may not be an open transaction.
*/
STREAM_OPEN
{
@Override
public State pullAll( SessionStateMachine ctx )
{
try
{
ctx.result( ctx.currentResult );
return discardAll( ctx );
}
catch ( Throwable e )
{
return error( ctx, e );
}
}
@Override
public State discardAll( SessionStateMachine ctx )
{
try
{
ctx.currentResult.close();
if ( !ctx.hasTransaction() )
{
return IDLE;
}
else if ( ctx.currentTransaction.transactionType() == implicit )
{
return IN_TRANSACTION.commitTransaction( ctx );
}
else
{
return IN_TRANSACTION;
}
}
catch ( Throwable e )
{
return error( ctx, e );
}
finally
{
ctx.currentResult = null;
}
}
@Override
public State reset( SessionStateMachine ctx )
{
// Do an extra reset, since discardAll may put us
// in the IN_TRANSACTION state
return discardAll( ctx ).reset( ctx );
}
},
/** An error has occurred, client must acknowledge it before anything else is allowed. */
ERROR
{
@Override
public State reset( SessionStateMachine ctx )
{
// There may still be a transaction open, so do
// an extra reset on the outcome of ackFailure to ensure we go
// to idle state.
return ackFailure( ctx ).reset( ctx );
}
@Override
public State ackFailure( SessionStateMachine ctx )
{
if( ctx.hasTransaction() )
{
return IN_TRANSACTION;
}
return IDLE;
}
@Override
protected State onNoImplementation( SessionStateMachine ctx, String command )
{
ctx.ignored();
return ERROR;
}
},
/**
* The state machine is in a temporary INTERRUPT state, and will ignore
* all messages until a RESET is received.
*/
INTERRUPTED
{
/**
* When we are in the interrupted state, we need RESET messages
* to clear that state.
*/
@Override
public State reset( SessionStateMachine ctx )
{
// If > 0 to guard against bugs making the counter negative
if( ctx.interruptCounter.get() > 0 )
{
if( ctx.interruptCounter.decrementAndGet() > 0 )
{
// This happens when the user sends multiple
// interrupts at the same time, we now demand
// an equivalent number of RESET until we go back
// to IDLE.
ctx.ignored();
return INTERRUPTED;
}
}
return IDLE;
}
@Override
public State interrupt( SessionStateMachine ctx )
{
return INTERRUPTED;
}
@Override
protected State onNoImplementation( SessionStateMachine ctx, String command )
{
ctx.ignored();
return INTERRUPTED;
}
},
/** The state machine is permanently stopped. */
STOPPED
{
@Override
public State halt( SessionStateMachine ctx )
{
return STOPPED;
}
@Override
protected State onNoImplementation( SessionStateMachine ctx, String command )
{
ctx.ignored();
return STOPPED;
}
};
// Operations that a session can perform. Individual states override these if they want to support them.
public State init( SessionStateMachine ctx, String clientName, Map<String,Object> authToken )
{
return onNoImplementation( ctx, "initializing the session" );
}
public State runStatement( SessionStateMachine ctx, String statement, Map<String,Object> params )
{
return onNoImplementation( ctx, "running a statement" );
}
public State pullAll( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "pulling full stream" );
}
public State discardAll( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "discarding remainder of stream" );
}
public State commitTransaction( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "committing transaction" );
}
public State rollbackTransaction( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "rolling back transaction" );
}
public State beginImplicitTransaction( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "beginning implicit transaction" );
}
public State beginTransaction( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "beginning implicit transaction" );
}
public State reset( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "resetting the current session" );
}
public State ackFailure( SessionStateMachine ctx )
{
return onNoImplementation( ctx, "acknowledging a failure" );
}
/**
* If the session has been interrupted, this will be invoked before *each*
* message that is processed after interruption, until the interrupt counter
* is reset back to 0. This exists to ensure we cleanly reset any current
* state, meaning the default implementation is the same as reset.
*/
public State interrupt( SessionStateMachine ctx )
{
reset( ctx );
return INTERRUPTED;
}
protected State onNoImplementation( SessionStateMachine ctx, String command )
{
String msg = "'" + command + "' cannot be done when a session is in the '" + ctx.state.name() + "' state.";
return error( ctx, new Neo4jError( Status.Request.Invalid, msg ) );
}
public State halt( SessionStateMachine ctx )
{
if ( ctx.currentTransaction != null )
{
try
{
ctx.currentTransaction.close();
}
catch ( Throwable e )
{
ctx.error( Neo4jError.from( e ) );
}
}
return STOPPED;
}
State error( SessionStateMachine ctx, Throwable err )
{
if( err instanceof AuthorizationViolationException &&
ctx.credentialsExpired )
{
// TODO: This is *way* too high up the stack to create this message, this should
// happen much further down.
return error( ctx, new Neo4jError( CredentialsExpired,
String.format("The credentials you provided were valid, but must be changed before you can " +
"use this instance. If this is the first time you are using Neo4j, this is to " +
"ensure you are not using the default credentials in production. If you are not " +
"using default credentials, you are getting this message because an administrator " +
"requires a password change.%n" +
"Changing your password is easy to do via the Neo4j Browser.%n" +
"If you are connecting via a shell or programmatically via a driver, " +
"just issue a `CALL dbms.changePassword('new password')` statement in the current " +
"session, and then restart your driver with the new password configured."),
err ) );
}
return error( ctx, Neo4jError.from( err ) );
}
State error( SessionStateMachine ctx, Neo4jError err )
{
ctx.spi.reportError( err );
State outcome = ERROR;
if ( ctx.hasTransaction() )
{
switch( ctx.currentTransaction.transactionType() )
{
case explicit:
ctx.currentTransaction.failure();
break;
case implicit:
try
{
ctx.currentTransaction.failure();
ctx.currentTransaction.close();
}
catch ( Throwable t )
{
ctx.spi.reportError( "While handling '" + err.status() + "', a second failure occurred when " +
"rolling back transaction: " + t.getMessage(), t );
}
finally
{
ctx.currentTransaction = null;
}
break;
}
}
ctx.error( err );
return outcome;
}
}
private final String id = UUID.randomUUID().toString();
/** A re-usable statement metadata instance that always represents the currently running statement */
private final StatementMetadata currentStatementMetadata = new StatementMetadata()
{
@Override
public String[] fieldNames()
{
return currentResult.fieldNames();
}
};
/**
* This is incremented each time {@link #interrupt()} is called,
* and decremented each time a {@link #reset(Object, Callback)} message
* arrives. When this is above 0, all messages will be ignored.
* This way, when a reset message arrives on the network, interrupt
* can be called to "purge" all the messages ahead of the reset message.
*/
private final AtomicInteger interruptCounter = new AtomicInteger();
/** The current session state */
private State state = State.UNINITIALIZED;
/** The current pending result, if present */
private RecordStream currentResult;
/** The current transaction, if present */
private KernelTransaction currentTransaction;
/** The current query source, if initialized */
private String currentQuerySource;
/** Callback poised to receive the next response */
private Callback currentCallback;
/** Callback attachment */
private Object currentAttachment;
/** The current session auth state to be used for starting transactions */
private AccessMode accessMode;
/**
* If the current user has provided valid but needs-to-be-changed credentials,
* this flag gets set. This is not awesome - it'd be better to have a special
* access mode for this state, that would help disambiguate from being unauthenticated
* as well. Did things this way to minimize risk of introducing bugs this late
* in the 3.0 cycle. A further note towards adding a special AccessMode is that
* we need to set things up to change access mode anyway whenever the user changes
* credentials or is upgraded. As it is now, a new session needs to be created.
*/
private boolean credentialsExpired;
/** These are the "external" actions the state machine can take */
private final SPI spi;
/**
* This SPI encapsulates the "external" actions the state machine can take.
* It exists for three reasons:
* 1) It makes it very clear what side-effects the SSM can have
* 2) It decouples the SSM from the actual components performing these operations
* 3) It makes it *much* easier to test the SSM without having to re-implement
* the whole database as mocks.
*
* If you are adding new functionality to the SSM where the new function needs
* to reach out to some component outside the SSM, please add it here. And when
* you do, please consider the law of demeter - if you are simply adding
* "getQueryEngine" to the SPI, you're doing it wrong, then we might as well
* have the full components as fields.
*/
interface SPI
{
String connectionDescriptor();
void reportError( Neo4jError err );
void reportError( String message, Throwable cause );
KernelTransaction beginTransaction( KernelTransaction.Type type, AccessMode mode );
void bindTransactionToCurrentThread( KernelTransaction tx );
void unbindTransactionFromCurrentThread();
RecordStream run( SessionStateMachine ctx, String statement, Map<String, Object> params )
throws KernelException;
AuthenticationResult authenticate( Map<String, Object> authToken ) throws AuthenticationException;
void udcRegisterClient( String clientName );
Statement currentStatement();
}
public SessionStateMachine( String connectionDescriptor, UsageData usageData, GraphDatabaseFacade db, ThreadToStatementContextBridge txBridge,
StatementRunner engine, LogService logging, Authentication authentication )
{
this( new StandardStateMachineSPI( connectionDescriptor, usageData, db, engine, logging, authentication, txBridge ));
}
public SessionStateMachine( SPI spi )
{
this.spi = spi;
this.accessMode = AccessMode.Static.NONE;
}
@Override
public String key()
{
return id;
}
public String connectionDescriptor()
{
return spi.connectionDescriptor();
}
private String querySource()
{
return currentQuerySource;
}
private void setQuerySourceFromClientNameAndPrincipal( String clientName, Object principal )
{
String principalName = principal == null ? "null" : principal.toString();
currentQuerySource = format( "bolt\t%s\t%s\t%s>", principalName, clientName, connectionDescriptor() );
}
@Override
public <A> void init( String clientName, Map<String,Object> authToken, A attachment, Callback<Boolean,A> callback )
{
before( attachment, callback );
try
{
state = state.init( this, clientName, authToken );
}
finally { after(); }
}
@Override
public <A> void run( String statement, Map<String,Object> params, A attachment,
Callback<StatementMetadata,A> callback )
{
before( attachment, callback );
try
{
state = state.runStatement( this, statement, params );
}
finally { after(); }
}
@Override
public <A> void pullAll( A attachment, Callback<RecordStream,A> callback )
{
before( attachment, callback );
try
{
state = state.pullAll( this );
}
finally { after(); }
}
@Override
public <A> void discardAll( A attachment, Callback<Void,A> callback )
{
before( attachment, callback );
try
{
state = state.discardAll( this );
}
finally { after(); }
}
@Override
public <A> void ackFailure( A attachment, Callback<Void,A> callback )
{
before( attachment, callback );
try
{
state = state.ackFailure( this );
}
finally { after(); }
}
@Override
public <A> void reset( A attachment, Callback<Void,A> callback )
{
before( attachment, callback );
try
{
state = state.reset( this );
}
finally { after(); }
}
@Override
public void interrupt()
{
// NOTE: This is a side-channel method call. You *cannot*
// mutate any of the regular state in the state machine
// from inside this method, it WILL lead to race conditions.
// Imagine this is always called from a separate thread, while
// the main session worker thread is actively working on mutating
// fields on the session.
interruptCounter.incrementAndGet();
// If there is currently a transaction running, terminate it
KernelTransaction tx = this.currentTransaction;
if(tx != null)
{
tx.markForTermination();
}
}
@Override
public void close()
{
before( null, null );
try
{
state = state.halt( this );
}
finally { after(); }
}
// Below are methods used from within the state machine, to alter state while its executing an action
@Override
public void beginImplicitTransaction()
{
state = state.beginImplicitTransaction( this );
}
@Override
public void beginTransaction()
{
state = state.beginTransaction( this );
}
@Override
public void commitTransaction()
{
state = state.commitTransaction( this );
}
@Override
public void rollbackTransaction()
{
state = state.rollbackTransaction( this );
}
@Override
public boolean hasTransaction()
{
return currentTransaction != null;
}
@Override
public QuerySession createSession( GraphDatabaseQueryService service, PropertyContainerLocker locker )
{
InternalTransaction transaction = service.beginTransaction( implicit, accessMode );
Neo4jTransactionalContext transactionalContext =
new Neo4jTransactionalContext( service, transaction, spi.currentStatement(), locker );
return new BoltQuerySession( transactionalContext, querySource() );
}
public State state()
{
return state;
}
@Override
public String toString()
{
return "Session[" + id + "," + state.name() + "]";
}
/**
* Set the callback to receive the next response. This will receive one completion or one failure, and then be
* detached again. This exists both to ensure that each callback only gets called once, as well as to avoid
* repeating the callback and attachments in every method signature in the state machine.
*/
private void before( Object attachment, Callback cb )
{
if ( cb != null )
{
cb.started( attachment );
}
if( interruptCounter.get() > 0 )
{
// Force into interrupted state. This is how we 'discover'
// that `interrupt` has been called.
// First reset, so we clean up any open resources
state = state.interrupt( this );
}
if ( hasTransaction() )
{
spi.bindTransactionToCurrentThread( currentTransaction );
}
assert this.currentCallback == null;
assert this.currentAttachment == null;
this.currentCallback = cb;
this.currentAttachment = attachment;
}
/** Signal to the currently attached client callback that the request has been processed */
private void after()
{
try
{
if ( currentCallback != null )
{
try
{
currentCallback.completed( currentAttachment );
}
finally
{
currentCallback = null;
currentAttachment = null;
}
}
}
finally
{
if ( hasTransaction() )
{
spi.unbindTransactionFromCurrentThread();
}
}
}
/** Forward an error to the currently attached callback */
private void error( Neo4jError err )
{
if ( err.status().code().classification() == Status.Classification.DatabaseError )
{
spi.reportError( err );
}
if ( currentCallback != null )
{
currentCallback.failure( err, currentAttachment );
}
}
/** Forward a result to the currently attached callback */
private void result( Object result ) throws Exception
{
if ( currentCallback != null )
{
currentCallback.result( result, currentAttachment );
}
}
/**
* A message is being ignored, because the state machine is waiting for an error to be acknowledged before it
* resumes processing.
*/
private void ignored()
{
if ( currentCallback != null )
{
currentCallback.ignored( currentAttachment );
}
}
private class BoltQuerySession extends QuerySession
{
private final String querySource;
public BoltQuerySession( Neo4jTransactionalContext transactionalContext, String querySource )
{
super( transactionalContext );
this.querySource = querySource;
}
@Override
public String toString()
{
return format( "bolt-session\t%s", querySource );
}
}
}