diff --git a/backend_test_suite.go b/backend_test_suite.go index 33d74c6..ac77e8a 100644 --- a/backend_test_suite.go +++ b/backend_test_suite.go @@ -35,7 +35,7 @@ type BackendTestSuite struct { } func (ts *BackendTestSuite) SetupSuite() { - ts.Trans = newFnMgr() + ts.Trans = newFnMgr("") ts.NotNil(ts.Gen) } diff --git a/bridge_test.go b/bridge_test.go index 80bf1ea..691e6d1 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -19,7 +19,7 @@ type bridgeTestSuite struct { func (ts *bridgeTestSuite) SetupSuite() { ts.eventMux = newMux() - ts.trans = newFnMgr() + ts.trans = newFnMgr("") } func (ts *bridgeTestSuite) TearDownSuite() { diff --git a/broker_test_suite.go b/broker_test_suite.go index 7a38429..e28c3dd 100644 --- a/broker_test_suite.go +++ b/broker_test_suite.go @@ -57,7 +57,7 @@ func (ts *BrokerTestSuite) SetupTest() { } ts.ConsumerNames = []string{} - ts.Trans = newFnMgr() + ts.Trans = newFnMgr("") } func (ts *BrokerTestSuite) TearDownTest() { diff --git a/dingo.go b/dingo.go index ff395e2..f4a35a1 100644 --- a/dingo.go +++ b/dingo.go @@ -100,21 +100,21 @@ type App struct { workers *_workers } -/*NewApp whose "nameOfBridge" refers to different modes of dingo: +/*NewApp whose "mode" refers to different modes of dingo: - "local": an App works in local mode, which is similar to other background worker framework. - "remote": an App works in remote(distributed) mode, brokers(ex. AMQP...) and backends(ex. redis..., if required) would be needed to work. */ -func NewApp(nameOfBridge string, cfg *Config) (app *App, err error) { +func NewApp(mode string, cfg *Config) (app *App, err error) { if cfg == nil { cfg = DefaultConfig() } v := &App{ objs: make(map[int]*_object), eventMux: newMux(), - trans: newFnMgr(), + trans: newFnMgr(mode), cfg: *cfg, } - v.b = newBridge(nameOfBridge, v.trans) + v.b = newBridge(mode, v.trans) // refer to 'ReadMostly' example in sync/atomic v.eventOut.Store(make(map[int]*_eventListener)) diff --git a/id_maker.go b/id_maker.go index 8acedc2..1540c0c 100644 --- a/id_maker.go +++ b/id_maker.go @@ -13,8 +13,10 @@ var ID = struct { Default int // an ID maker implemented via uuid4 UUID int + // an ID maker implemented by atomic.AddInt64 + SEQ int }{ - 0, 1, + 0, 1, 2, } /*IDMaker is an object that can generate a series of identiy, typed as string. diff --git a/mapper_test.go b/mapper_test.go index 912adad..1b6fed0 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -20,7 +20,7 @@ type mapperTestSuite struct { func TestMapperSuite(t *testing.T) { suite.Run(t, &mapperTestSuite{ - _trans: newFnMgr(), + _trans: newFnMgr(""), _hooks: newLocalBridge().(exHooks), _tasks: make(chan *Task, 5), _countOfMappers: 3, diff --git a/mgr.go b/mgr.go index 93dde74..84b8ac1 100644 --- a/mgr.go +++ b/mgr.go @@ -28,7 +28,7 @@ type fnMgr struct { fn2opt atomic.Value } -func newFnMgr() (c *fnMgr) { +func newFnMgr(mode string) (c *fnMgr) { c = &fnMgr{} // init for marshaller's' @@ -66,7 +66,13 @@ func newFnMgr() (c *fnMgr) { defer c.imsLock.Unlock() ims[ID.UUID] = &uuidMaker{} - ims[ID.Default] = ims[ID.UUID] + ims[ID.SEQ] = &SeqIDMaker{} + switch mode { + case "local": + ims[ID.Default] = ims[ID.SEQ] + default: + ims[ID.Default] = ims[ID.UUID] + } c.ims.Store(ims) // init map from name of function to options diff --git a/mgr_test.go b/mgr_test.go index b4b11f6..86a2e3d 100644 --- a/mgr_test.go +++ b/mgr_test.go @@ -10,7 +10,7 @@ import ( func TestMgrMarshallers(t *testing.T) { ass := assert.New(t) - trans := newFnMgr() + trans := newFnMgr("") ass.Nil(trans.Register("TestMgrMarshallers", func() {})) ass.Nil(trans.SetMarshaller("TestMgrMarshallers", Encode.JSON, Encode.GOB)) task, err := trans.ComposeTask("TestMgrMarshallers", nil, []interface{}{float64(1)}) @@ -64,7 +64,7 @@ func TestMgrInvokers(t *testing.T) { } ass := assert.New(t) - trans := newFnMgr() + trans := newFnMgr("") ass.Nil(trans.Register("TestMgrInvokers", fn)) ass.Nil(trans.SetMarshaller("TestMgrInvokers", Encode.JSON, Encode.JSON)) @@ -91,7 +91,7 @@ func TestMgrInvokers(t *testing.T) { func TestMgrOption(t *testing.T) { ass := assert.New(t) - trans := newFnMgr() + trans := newFnMgr("") // name doesn't register ass.NotNil(trans.SetOption("TestMgrOption", DefaultOption())) @@ -118,7 +118,7 @@ func TestMgrOption(t *testing.T) { func TestMgrRegister(t *testing.T) { ass := assert.New(t) - trans := newFnMgr() + trans := newFnMgr("") // register a function, with not-existed marshaller id. ass.Nil(trans.Register("TestMgrResgister", func() {})) @@ -141,7 +141,7 @@ func (idm *testAlwaysErrorIDMaker) NewID() (string, error) { return "", errors.N func TestMgrIDMaker(t *testing.T) { ass := assert.New(t) - trans := newFnMgr() + trans := newFnMgr("") // register a function ass.Nil(trans.Register("TestMgrIDMaker", func() {})) diff --git a/result_test.go b/result_test.go index bbf14d1..cd88152 100644 --- a/result_test.go +++ b/result_test.go @@ -16,7 +16,7 @@ type resultTestSuite struct { func TestResultSuite(t *testing.T) { suite.Run(t, &resultTestSuite{ - trans: newFnMgr(), + trans: newFnMgr(""), }) } diff --git a/worker_test.go b/worker_test.go index 1ed3a33..515be77 100644 --- a/worker_test.go +++ b/worker_test.go @@ -18,7 +18,7 @@ type workerTestSuite struct { func TestWorkerSuite(t *testing.T) { suite.Run(t, &workerTestSuite{ - _trans: newFnMgr(), + _trans: newFnMgr(""), _hooks: newLocalBridge().(exHooks), }) }