Skip to content

Commit

Permalink
refactor(plc4go/spi): move transaction manager to own package
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed May 31, 2023
1 parent 4389991 commit 09147a8
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package spi
package transactions

import (
"container/list"
Expand All @@ -42,7 +42,7 @@ func init() {
sharedExecutorInstance.Start()
}

type RequestTransactionRunnable func(transaction RequestTransaction)
type RequestTransactionRunnable func(RequestTransaction)

// RequestTransaction represents a transaction
type RequestTransaction interface {
Expand Down Expand Up @@ -107,7 +107,7 @@ type requestTransaction struct {

type requestTransactionManager struct {
runningRequests []*requestTransaction
// How many Transactions are allowed to run at the same time?
// How many transactions are allowed to run at the same time?
numberOfConcurrentRequests int
// Assigns each request a Unique Transaction Id, especially important for failure handling
transactionId int32
Expand Down Expand Up @@ -139,12 +139,12 @@ func (r *requestTransactionManager) SetNumberOfConcurrentRequests(numberOfConcur
}

func (r *requestTransactionManager) submitTransaction(transaction *requestTransaction) {
// Add this Request with this transaction i the Worklog
// Put Transaction into Worklog
// Add this Request with the transaction i the work log
// Put Transaction into work log
r.workLogMutex.Lock()
r.workLog.PushFront(transaction)
r.workLogMutex.Unlock()
// Try to Process the Worklog
// Try to Process the work log
r.processWorklog()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package spi
package transactions

import (
"container/list"
Expand Down Expand Up @@ -443,7 +443,7 @@ func Test_requestTransaction_AwaitCompletion(t1 *testing.T) {
r := &requestTransaction{}
go func() {
time.Sleep(100 * time.Millisecond)
// We fake a ending transaction like that
// We fake an ending transaction like that
r.transactionId = 1
}()
return r
Expand Down
132 changes: 132 additions & 0 deletions plc4go/spi/transactions/mock_CompletionFuture_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions plc4go/spi/transactions/mock_requirements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* https://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.
*/

package transactions

import (
"github.com/apache/plc4x/plc4go/spi/utils"
)

// Note this file is a Helper for mockery to generate use mocks from other package

// Deprecated: don't use it in productive code
type CompletionFuture interface {
utils.CompletionFuture
}

0 comments on commit 09147a8

Please sign in to comment.