Skip to content

Commit

Permalink
[FAB-8396] Abstract Event Client
Browse files Browse the repository at this point in the history
Implement an abstract event client that
connects to a GRPC event server and manages
the connection/stream. This client may be
extended by protocol-specific implementations
(i.e. Event Hub and Deliver Service).

Also moved files to new package structure.

Change-Id: I489fd7e6c5780fda2e43412c8aadf732343b8e36
Signed-off-by: Bob Stasyszyn <Bob.Stasyszyn@securekey.com>
  • Loading branch information
bstasyszyn committed Feb 23, 2018
1 parent f0853f3 commit 36f1d9d
Show file tree
Hide file tree
Showing 34 changed files with 3,137 additions and 97 deletions.
Expand Up @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package apifabclient
package fab

import (
cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -79,6 +79,16 @@ type EventService interface {
Unregister(reg Registration)
}

// ConnectionEvent is sent when the client disconnects from or
// reconnects to the event server. Connected == true means that the
// client has connected, whereas Connected == false means that the
// client has disconnected. In the disconnected case, Err contains
// the disconnect error.
type ConnectionEvent struct {
Connected bool
Err error
}

// EventClient is a client that connects to a peer and receives channel events
// such as block, filtered block, chaincode, and transaction status events.
type EventClient interface {
Expand All @@ -90,4 +100,9 @@ type EventClient interface {
// Close closes the connection to the event server and releases all resources.
// Once this function is invoked the client may no longer be used.
Close()

// RegisterConnectionEvent registers a connection event. The returned
// ConnectionEvent channel is called whenever the client clients to
// or disconnects from the event server
RegisterConnectionEvent() (Registration, chan ConnectionEvent, error)
}
25 changes: 25 additions & 0 deletions pkg/fab/events/api/connection.go
@@ -0,0 +1,25 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package api

import (
"github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
)

// Connection defines the functions for an event server connection
type Connection interface {
// Receive sends events to the given channel
Receive(chan<- interface{})
// Close closes the connection
Close()
// Closed return true if the connection is closed
Closed() bool
}

// ConnectionProvider creates a Connection.
type ConnectionProvider func(channelID string, context context.Context, peer fab.Peer) (Connection, error)

0 comments on commit 36f1d9d

Please sign in to comment.