Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from mongodb/description-change-events
Add description change events.
- Loading branch information
Showing
9 changed files
with
277 additions
and
24 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
# Copyright (C) 2009-2014 MongoDB, Inc. | |||
# | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | |||
# You may obtain a copy of the License at | |||
# | |||
# http://www.apache.org/licenses/LICENSE-2.0 | |||
# | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
|||
module Mongo | |||
module Event | |||
|
|||
# This handles host added events for server descriptions. | |||
# | |||
# @since 3.0.0 | |||
class HostAdded | |||
|
|||
# @return [ Mongo::Server ] server The event publisher. | |||
attr_reader :server | |||
|
|||
# Initialize the new host added event handler. | |||
# | |||
# @example Create the new handler. | |||
# HostAdded.new(server) | |||
# | |||
# @param [ Mongo::Server ] server The server to publish from. | |||
# | |||
# @since 3.0.0 | |||
def initialize(server) | |||
@server = server | |||
end | |||
|
|||
def handle(address) | |||
# @todo: Log the description change here. | |||
server.publish(Event::SERVER_ADDED, address) | |||
end | |||
end | |||
end | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
# Copyright (C) 2009-2014 MongoDB, Inc. | |||
# | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | |||
# You may obtain a copy of the License at | |||
# | |||
# http://www.apache.org/licenses/LICENSE-2.0 | |||
# | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
|||
module Mongo | |||
module Event | |||
|
|||
# This handles host removed events for server descriptions. | |||
# | |||
# @since 3.0.0 | |||
class HostRemoved | |||
|
|||
# @return [ Mongo::Server ] server The event publisher. | |||
attr_reader :server | |||
|
|||
# Initialize the new host removed event handler. | |||
# | |||
# @example Create the new handler. | |||
# HostRemoved.new(server) | |||
# | |||
# @param [ Mongo::Server ] server The server to publish from. | |||
# | |||
# @since 3.0.0 | |||
def initialize(server) | |||
@server = server | |||
end | |||
|
|||
def handle(address) | |||
# @todo: Log the description change here. | |||
server.publish(Event::SERVER_REMOVED, address) | |||
end | |||
end | |||
end | |||
end |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
require 'spec_helper' | |||
|
|||
describe Mongo::Event::HostAdded do | |||
|
|||
describe '#handle' do | |||
|
|||
let(:server) do | |||
double('server') | |||
end | |||
|
|||
let(:handler) do | |||
described_class.new(server) | |||
end | |||
|
|||
it 'publishes the event from the server' do | |||
expect(server).to receive(:publish).with(Mongo::Event::SERVER_ADDED, 'test') | |||
handler.handle('test') | |||
end | |||
end | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
require 'spec_helper' | |||
|
|||
describe Mongo::Event::HostRemoved do | |||
|
|||
describe '#handle' do | |||
|
|||
let(:server) do | |||
double('server') | |||
end | |||
|
|||
let(:handler) do | |||
described_class.new(server) | |||
end | |||
|
|||
it 'publishes the event from the server' do | |||
expect(server).to receive(:publish).with(Mongo::Event::SERVER_REMOVED, 'test') | |||
handler.handle('test') | |||
end | |||
end | |||
end |
Oops, something went wrong.