Skip to content

Commit

Permalink
Merge pull request #871 from fluent/separate-msgpack-factory-from-engine
Browse files Browse the repository at this point in the history
Separate msgpack_factory from Engine to a file
  • Loading branch information
tagomoris committed Mar 31, 2016
2 parents 0198b61 + fb09f3b commit 052d791
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
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

0 comments on commit 052d791

Please sign in to comment.