Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce "EngineNode" which is a proxy (or an agent) for a node
Conflicts: lib/droonga/engine_state.rb
- Loading branch information
Showing
4 changed files
with
119 additions
and
78 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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright (C) 2015 Droonga Project | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License version 2.1 as published by the Free Software Foundation. | ||
| # | ||
| # This library 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 | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
|
||
| require "droonga/node_metadata" | ||
|
|
||
| module Droonga | ||
| class EngineNode | ||
| attr_reader :name | ||
|
|
||
| def initialize(name, state) | ||
| @name = name | ||
| @state = state | ||
| end | ||
|
|
||
| def live? | ||
| @state.nil? or @state["live"] | ||
| end | ||
|
|
||
| def dead? | ||
| not live? | ||
| end | ||
|
|
||
| def service_provider? | ||
| role == NodeMetadata::Role::SERVICE_PROVIDER | ||
| end | ||
|
|
||
| def absorb_source? | ||
| role == NodeMetadata::Role::ABSORB_SOURCE | ||
| end | ||
|
|
||
| def absorb_destination? | ||
| role == NodeMetadata::Role::ABSORB_DESTINATION | ||
| end | ||
|
|
||
| def role | ||
| if @state | ||
| @state["role"] | ||
| else | ||
| NodeMetadata::Role::SERVICE_PROVIDER | ||
| end | ||
| end | ||
|
|
||
| def forwardable? | ||
| not dead? | ||
| end | ||
|
|
||
| def writable_by?(sender_role) | ||
| case sender_role | ||
| when NodeMetadata::Role::SERVICE_PROVIDER | ||
| true | ||
| when NodeMetadata::Role::ABSORB_SOURCE | ||
| absorb_source? | ||
| when NodeMetadata::Role::ABSORB_DESTINATION | ||
| absorb_destination? | ||
| else | ||
| false | ||
| 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