Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate msgpack_factory from Engine to a file #871

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/fluent/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@

require 'socket'

require 'msgpack'
require 'cool.io'

require 'fluent/config'
require 'fluent/event'
require 'fluent/event_router'
require 'fluent/msgpack_factory'
require 'fluent/root_agent'
require 'fluent/time'
require 'fluent/system_config'
require 'fluent/plugin'

module Fluent
class EngineClass
include Fluent::MessagePackFactory::Mixin

def initialize
@root_agent = nil
@event_router = nil
Expand All @@ -41,8 +43,6 @@ def initialize

@suppress_config_dump = false

@msgpack_factory = MessagePack::Factory.new
@msgpack_factory.register_type(Fluent::EventTime::TYPE, Fluent::EventTime)
@system_config = SystemConfig.new
end

Expand All @@ -51,7 +51,6 @@ def initialize

attr_reader :root_agent
attr_reader :matches, :sources
attr_reader :msgpack_factory
attr_reader :system_config

def init(system_config)
Expand All @@ -69,6 +68,8 @@ def init(system_config)

@root_agent = RootAgent.new(@system_config)

MessagePackFactory.init

self
end

Expand Down
62 changes: 62 additions & 0 deletions lib/fluent/msgpack_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Fluentd
#
# 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.
#

require 'msgpack'
require 'fluent/time'

module Fluent
module MessagePackFactory
@@engine_factory = nil

module Mixin
def msgpack_factory
MessagePackFactory.engine_factory
end

def msgpack_packer(*args)
msgpack_factory.packer(*args)
end

def msgpack_unpacker(*args)
msgpack_factory.unpacker(*args)
end
end

def self.engine_factory
@@engine_factory || factory
end

def self.factory
factory = MessagePack::Factory.new
factory.register_type(Fluent::EventTime::TYPE, Fluent::EventTime)
factory
end

def self.packer(*args)
factory.packer(*args)
end

def self.unpacker(*args)
factory.unpacker(*args)
end

def self.init
factory = MessagePack::Factory.new
factory.register_type(Fluent::EventTime::TYPE, Fluent::EventTime)
@@engine_factory = factory
end
end
end