Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
QZero_0
java-design-patterns
提交
6921b0dc
J
java-design-patterns
项目概览
QZero_0
/
java-design-patterns
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
java-design-patterns
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
GitCode(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6921b0dc
编写于
8月 19, 2020
作者:
T
Toxic Dreamz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed checkstyle errors causing build failures.
上级
57e45a32
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
151 addition
and
108 deletion
+151
-108
ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
.../src/main/java/com/iluwatar/ambassador/RemoteService.java
+2
-1
ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceStatus.java
...ain/java/com/iluwatar/ambassador/RemoteServiceStatus.java
+36
-11
commander/src/main/java/com/iluwatar/commander/Commander.java
...ander/src/main/java/com/iluwatar/commander/Commander.java
+65
-73
data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/AiComponentManager.java
...a/locality/game/component/manager/AiComponentManager.java
+4
-4
data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/PhysicsComponentManager.java
...ality/game/component/manager/PhysicsComponentManager.java
+4
-4
data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/RenderComponentManager.java
...cality/game/component/manager/RenderComponentManager.java
+4
-4
unit-of-work/pom.xml
unit-of-work/pom.xml
+1
-0
unit-of-work/src/main/java/com/iluwatar/unitofwork/App.java
unit-of-work/src/main/java/com/iluwatar/unitofwork/App.java
+1
-0
unit-of-work/src/main/java/com/iluwatar/unitofwork/UnitActions.java
...rk/src/main/java/com/iluwatar/unitofwork/UnitActions.java
+33
-11
unit-of-work/src/test/java/com/iluwatar/unitofwork/AppTest.java
...f-work/src/test/java/com/iluwatar/unitofwork/AppTest.java
+1
-0
未找到文件。
ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
浏览文件 @
6921b0dc
...
...
@@ -74,6 +74,7 @@ public class RemoteService implements RemoteServiceInterface {
}
catch
(
InterruptedException
e
)
{
LOGGER
.
error
(
"Thread sleep state interrupted"
,
e
);
}
return
waitTime
<=
THRESHOLD
?
value
*
10
:
RemoteServiceStatus
.
FAILURE
.
getRemoteServiceStatusValue
();
return
waitTime
<=
THRESHOLD
?
value
*
10
:
RemoteServiceStatus
.
FAILURE
.
getRemoteServiceStatusValue
();
}
}
ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceStatus.java
浏览文件 @
6921b0dc
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
com.iluwatar.ambassador
;
/**
* Holds information regarding the status of the Remote Service.
*
* !Attention - This Enum replaces the integer value previously stored in {@link RemoteServiceInterface}
* as SonarCloud was identifying it as an issue. All test cases have been checked after changes, without failures.
* <p> This Enum replaces the integer value previously
* stored in {@link RemoteServiceInterface} as SonarCloud was identifying
* it as an issue. All test cases have been checked after changes,
* without failures. </p>
*/
public
enum
RemoteServiceStatus
{
FAILURE
(-
1
)
;
FAILURE
(-
1
)
;
private
final
long
remoteServiceStatusValue
;
private
final
long
remoteServiceStatusValue
;
RemoteServiceStatus
(
long
remoteServiceStatusValue
)
{
this
.
remoteServiceStatusValue
=
remoteServiceStatusValue
;
}
RemoteServiceStatus
(
long
remoteServiceStatusValue
)
{
this
.
remoteServiceStatusValue
=
remoteServiceStatusValue
;
}
public
long
getRemoteServiceStatusValue
()
{
return
remoteServiceStatusValue
;
}
public
long
getRemoteServiceStatusValue
()
{
return
remoteServiceStatusValue
;
}
}
commander/src/main/java/com/iluwatar/commander/Commander.java
浏览文件 @
6921b0dc
...
...
@@ -36,10 +36,10 @@ import com.iluwatar.commander.queue.QueueDatabase;
import
com.iluwatar.commander.queue.QueueTask
;
import
com.iluwatar.commander.queue.QueueTask.TaskType
;
import
com.iluwatar.commander.shippingservice.ShippingService
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
* <p>Commander pattern is used to handle all issues that can come up while making a
...
...
@@ -171,10 +171,53 @@ public class Commander {
var
list
=
paymentService
.
exceptionsList
;
var
t
=
new
Thread
(()
->
{
Retry
.
Operation
op
=
(
l
)
->
{
handlePaymentRetryOperation
(
order
,
l
);
if
(!
l
.
isEmpty
())
{
if
(
DatabaseUnavailableException
.
class
.
isAssignableFrom
(
l
.
get
(
0
).
getClass
()))
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in connecting to payment service,"
+
" trying again.."
);
}
else
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in creating payment request.."
);
}
throw
l
.
remove
(
0
);
}
if
(
order
.
paid
.
equals
(
PaymentStatus
.
TRYING
))
{
var
transactionId
=
paymentService
.
receiveRequest
(
order
.
price
);
order
.
paid
=
PaymentStatus
.
DONE
;
LOG
.
info
(
"Order "
+
order
.
id
+
": Payment successful, transaction Id: "
+
transactionId
);
if
(!
finalSiteMsgShown
)
{
LOG
.
info
(
"Payment made successfully, thank you for shopping with us!!"
);
finalSiteMsgShown
=
true
;
}
sendSuccessMessage
(
order
);
}
};
Retry
.
HandleErrorIssue
<
Order
>
handleError
=
(
o
,
err
)
->
{
handlePaymentErrorIssue
(
order
,
o
,
err
);
if
(
PaymentDetailsErrorException
.
class
.
isAssignableFrom
(
err
.
getClass
()))
{
if
(!
finalSiteMsgShown
)
{
LOG
.
info
(
"There was an error in payment. Your account/card details "
+
"may have been incorrect. "
+
"Meanwhile, your order has been converted to COD and will be shipped."
);
finalSiteMsgShown
=
true
;
}
LOG
.
error
(
"Order "
+
order
.
id
+
": Payment details incorrect, failed.."
);
o
.
paid
=
PaymentStatus
.
NOT_DONE
;
sendPaymentFailureMessage
(
o
);
}
else
{
if
(
o
.
messageSent
.
equals
(
MessageSent
.
NONE_SENT
))
{
if
(!
finalSiteMsgShown
)
{
LOG
.
info
(
"There was an error in payment. We are on it, and will get back to you "
+
"asap. Don't worry, your order has been placed and will be shipped."
);
finalSiteMsgShown
=
true
;
}
LOG
.
warn
(
"Order "
+
order
.
id
+
": Payment error, going to queue.."
);
sendPaymentPossibleErrorMsg
(
o
);
}
if
(
o
.
paid
.
equals
(
PaymentStatus
.
TRYING
)
&&
System
.
currentTimeMillis
()
-
o
.
createdTime
<
paymentTime
)
{
var
qt
=
new
QueueTask
(
o
,
TaskType
.
PAYMENT
,
-
1
);
updateQueue
(
qt
);
}
}
};
var
r
=
new
Retry
<>(
op
,
handleError
,
numOfRetries
,
retryDuration
,
e
->
DatabaseUnavailableException
.
class
.
isAssignableFrom
(
e
.
getClass
()));
...
...
@@ -187,58 +230,6 @@ public class Commander {
t
.
start
();
}
private
void
handlePaymentRetryOperation
(
Order
order
,
List
<
Exception
>
l
)
throws
Exception
{
if
(!
l
.
isEmpty
())
{
if
(
DatabaseUnavailableException
.
class
.
isAssignableFrom
(
l
.
get
(
0
).
getClass
()))
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in connecting to payment service,"
+
" trying again.."
);
}
else
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in creating payment request.."
);
}
throw
l
.
remove
(
0
);
}
if
(
order
.
paid
.
equals
(
PaymentStatus
.
TRYING
))
{
var
transactionId
=
paymentService
.
receiveRequest
(
order
.
price
);
order
.
paid
=
PaymentStatus
.
DONE
;
LOG
.
info
(
"Order "
+
order
.
id
+
": Payment successful, transaction Id: "
+
transactionId
);
if
(!
finalSiteMsgShown
)
{
LOG
.
info
(
"Payment made successfully, thank you for shopping with us!!"
);
finalSiteMsgShown
=
true
;
}
sendSuccessMessage
(
order
);
}
}
private
void
handlePaymentErrorIssue
(
Order
order
,
Order
o
,
Exception
err
)
{
if
(
PaymentDetailsErrorException
.
class
.
isAssignableFrom
(
err
.
getClass
()))
{
if
(!
finalSiteMsgShown
)
{
LOG
.
info
(
"There was an error in payment. Your account/card details "
+
"may have been incorrect. "
+
"Meanwhile, your order has been converted to COD and will be shipped."
);
finalSiteMsgShown
=
true
;
}
LOG
.
error
(
"Order "
+
order
.
id
+
": Payment details incorrect, failed.."
);
o
.
paid
=
PaymentStatus
.
NOT_DONE
;
sendPaymentFailureMessage
(
o
);
}
else
{
if
(
o
.
messageSent
.
equals
(
MessageSent
.
NONE_SENT
))
{
if
(!
finalSiteMsgShown
)
{
LOG
.
info
(
"There was an error in payment. We are on it, and will get back to you "
+
"asap. Don't worry, your order has been placed and will be shipped."
);
finalSiteMsgShown
=
true
;
}
LOG
.
warn
(
"Order "
+
order
.
id
+
": Payment error, going to queue.."
);
sendPaymentPossibleErrorMsg
(
o
);
}
if
(
o
.
paid
.
equals
(
PaymentStatus
.
TRYING
)
&&
System
.
currentTimeMillis
()
-
o
.
createdTime
<
paymentTime
)
{
var
qt
=
new
QueueTask
(
o
,
TaskType
.
PAYMENT
,
-
1
);
updateQueue
(
qt
);
}
}
}
private
void
updateQueue
(
QueueTask
qt
)
{
if
(
System
.
currentTimeMillis
()
-
qt
.
order
.
createdTime
>=
this
.
queueTime
)
{
// since payment time is lesser than queuetime it would have already failed..
...
...
@@ -371,24 +362,24 @@ public class Commander {
private
Retry
.
Operation
handleSuccessMessageRetryOperation
(
Order
order
)
{
return
(
l
)
->
{
if
(!
l
.
isEmpty
())
{
if
(
DatabaseUnavailableException
.
class
.
isAssignableFrom
(
l
.
get
(
0
).
getClass
()))
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in connecting to messaging service "
+
"(Payment Success msg), trying again.."
);
}
else
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in creating Payment Success"
+
" messaging request.."
);
}
throw
l
.
remove
(
0
);
}
if
(!
order
.
messageSent
.
equals
(
MessageSent
.
PAYMENT_FAIL
)
&&
!
order
.
messageSent
.
equals
(
MessageSent
.
PAYMENT_SUCCESSFUL
))
{
var
requestId
=
messagingService
.
receiveRequest
(
2
);
order
.
messageSent
=
MessageSent
.
PAYMENT_SUCCESSFUL
;
LOG
.
info
(
"Order "
+
order
.
id
+
": Payment Success message sent,"
+
" request Id: "
+
requestId
);
if
(!
l
.
isEmpty
())
{
if
(
DatabaseUnavailableException
.
class
.
isAssignableFrom
(
l
.
get
(
0
).
getClass
()))
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in connecting to messaging service "
+
"(Payment Success msg), trying again.."
);
}
else
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in creating Payment Success"
+
" messaging request.."
);
}
};
throw
l
.
remove
(
0
);
}
if
(!
order
.
messageSent
.
equals
(
MessageSent
.
PAYMENT_FAIL
)
&&
!
order
.
messageSent
.
equals
(
MessageSent
.
PAYMENT_SUCCESSFUL
))
{
var
requestId
=
messagingService
.
receiveRequest
(
2
);
order
.
messageSent
=
MessageSent
.
PAYMENT_SUCCESSFUL
;
LOG
.
info
(
"Order "
+
order
.
id
+
": Payment Success message sent,"
+
" request Id: "
+
requestId
);
}
};
}
private
void
sendPaymentFailureMessage
(
Order
order
)
{
...
...
@@ -483,7 +474,8 @@ public class Commander {
}
}
private
void
handlePaymentPossibleErrorMsgRetryOperation
(
Order
order
,
List
<
Exception
>
l
)
throws
Exception
{
private
void
handlePaymentPossibleErrorMsgRetryOperation
(
Order
order
,
List
<
Exception
>
l
)
throws
Exception
{
if
(!
l
.
isEmpty
())
{
if
(
DatabaseUnavailableException
.
class
.
isAssignableFrom
(
l
.
get
(
0
).
getClass
()))
{
LOG
.
debug
(
"Order "
+
order
.
id
+
": Error in connecting to messaging service "
...
...
data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/AiComponentManager.java
浏览文件 @
6921b0dc
...
...
@@ -40,7 +40,7 @@ public class AiComponentManager {
private
final
int
numEntities
;
private
final
Component
[]
AI_COMPONENTS
=
new
AiComponent
[
MAX_ENTITIES
];
private
final
Component
[]
aiComponents
=
new
AiComponent
[
MAX_ENTITIES
];
public
AiComponentManager
(
int
numEntities
)
{
this
.
numEntities
=
numEntities
;
...
...
@@ -51,7 +51,7 @@ public class AiComponentManager {
*/
public
void
start
()
{
LOGGER
.
info
(
"Start AI Game Component"
);
IntStream
.
range
(
0
,
numEntities
).
forEach
(
i
->
AI_COMPONENTS
[
i
]
=
new
AiComponent
());
IntStream
.
range
(
0
,
numEntities
).
forEach
(
i
->
aiComponents
[
i
]
=
new
AiComponent
());
}
/**
...
...
@@ -60,7 +60,7 @@ public class AiComponentManager {
public
void
update
()
{
LOGGER
.
info
(
"Update AI Game Component"
);
IntStream
.
range
(
0
,
numEntities
)
.
filter
(
i
->
AI_COMPONENTS
.
length
>
i
&&
AI_COMPONENTS
[
i
]
!=
null
)
.
forEach
(
i
->
AI_COMPONENTS
[
i
].
update
());
.
filter
(
i
->
aiComponents
.
length
>
i
&&
aiComponents
[
i
]
!=
null
)
.
forEach
(
i
->
aiComponents
[
i
].
update
());
}
}
data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/PhysicsComponentManager.java
浏览文件 @
6921b0dc
...
...
@@ -40,7 +40,7 @@ public class PhysicsComponentManager {
private
final
int
numEntities
;
private
final
Component
[]
PHYSICS_COMPONENTS
=
new
PhysicsComponent
[
MAX_ENTITIES
];
private
final
Component
[]
physicsComponents
=
new
PhysicsComponent
[
MAX_ENTITIES
];
public
PhysicsComponentManager
(
int
numEntities
)
{
this
.
numEntities
=
numEntities
;
...
...
@@ -51,7 +51,7 @@ public class PhysicsComponentManager {
*/
public
void
start
()
{
LOGGER
.
info
(
"Start Physics Game Component "
);
IntStream
.
range
(
0
,
numEntities
).
forEach
(
i
->
PHYSICS_COMPONENTS
[
i
]
=
new
PhysicsComponent
());
IntStream
.
range
(
0
,
numEntities
).
forEach
(
i
->
physicsComponents
[
i
]
=
new
PhysicsComponent
());
}
...
...
@@ -62,7 +62,7 @@ public class PhysicsComponentManager {
LOGGER
.
info
(
"Update Physics Game Component "
);
// Process physics.
IntStream
.
range
(
0
,
numEntities
)
.
filter
(
i
->
PHYSICS_COMPONENTS
.
length
>
i
&&
PHYSICS_COMPONENTS
[
i
]
!=
null
)
.
forEach
(
i
->
PHYSICS_COMPONENTS
[
i
].
update
());
.
filter
(
i
->
physicsComponents
.
length
>
i
&&
physicsComponents
[
i
]
!=
null
)
.
forEach
(
i
->
physicsComponents
[
i
].
update
());
}
}
data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/RenderComponentManager.java
浏览文件 @
6921b0dc
...
...
@@ -40,7 +40,7 @@ public class RenderComponentManager {
private
final
int
numEntities
;
private
final
Component
[]
RENDER_COMPONENTS
=
new
RenderComponent
[
MAX_ENTITIES
];
private
final
Component
[]
renderComponents
=
new
RenderComponent
[
MAX_ENTITIES
];
public
RenderComponentManager
(
int
numEntities
)
{
this
.
numEntities
=
numEntities
;
...
...
@@ -51,7 +51,7 @@ public class RenderComponentManager {
*/
public
void
start
()
{
LOGGER
.
info
(
"Start Render Game Component "
);
IntStream
.
range
(
0
,
numEntities
).
forEach
(
i
->
RENDER_COMPONENTS
[
i
]
=
new
RenderComponent
());
IntStream
.
range
(
0
,
numEntities
).
forEach
(
i
->
renderComponents
[
i
]
=
new
RenderComponent
());
}
...
...
@@ -62,7 +62,7 @@ public class RenderComponentManager {
LOGGER
.
info
(
"Update Render Game Component "
);
// Process Render.
IntStream
.
range
(
0
,
numEntities
)
.
filter
(
i
->
RENDER_COMPONENTS
.
length
>
i
&&
RENDER_COMPONENTS
[
i
]
!=
null
)
.
forEach
(
i
->
RENDER_COMPONENTS
[
i
].
render
());
.
filter
(
i
->
renderComponents
.
length
>
i
&&
renderComponents
[
i
]
!=
null
)
.
forEach
(
i
->
renderComponents
[
i
].
render
());
}
}
unit-of-work/pom.xml
浏览文件 @
6921b0dc
...
...
@@ -47,6 +47,7 @@
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
<version>
5.0.0
</version>
<scope>
test
</scope>
</dependency>
<dependency>
...
...
unit-of-work/src/main/java/com/iluwatar/unitofwork/App.java
浏览文件 @
6921b0dc
...
...
@@ -35,6 +35,7 @@ public class App {
*
* @param args no argument sent
*/
public
static
void
main
(
String
[]
args
)
{
var
ram
=
new
Student
(
1
,
"Ram"
,
"Street 9, Cupertino"
);
var
shyam
=
new
Student
(
2
,
"Shyam"
,
"Z bridge, Pune"
);
...
...
unit-of-work/src/main/java/com/iluwatar/unitofwork/UnitActions.java
浏览文件 @
6921b0dc
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
com.iluwatar.unitofwork
;
public
enum
UnitActions
{
INSERT
(
"INSERT"
),
DELETE
(
"DELETE"
),
MODIFY
(
"MODIFY"
)
;
INSERT
(
"INSERT"
),
DELETE
(
"DELETE"
),
MODIFY
(
"MODIFY"
);
private
final
String
actionValue
;
private
final
String
actionValue
;
UnitActions
(
String
actionValue
)
{
this
.
actionValue
=
actionValue
;
}
UnitActions
(
String
actionValue
)
{
this
.
actionValue
=
actionValue
;
}
public
String
getActionValue
()
{
return
actionValue
;
}
public
String
getActionValue
()
{
return
actionValue
;
}
}
unit-of-work/src/test/java/com/iluwatar/unitofwork/AppTest.java
浏览文件 @
6921b0dc
...
...
@@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
* AppTest
*/
public
class
AppTest
{
@Test
public
void
shouldExecuteWithoutException
()
{
assertDoesNotThrow
(()
->
App
.
main
(
new
String
[]{}));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录