Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9a45c807
authored
Dec 14, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queueueue
1 parent
72327b43
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
8 deletions
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/QueueBeanLocal.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/MenuBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/QueueBean.java
code/moya-web/WebContent/neomap/notenoughslots.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/map/AjaxMapView.java
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/QueueBeanLocal.java
View file @
9a45c80
...
@@ -19,4 +19,9 @@ public interface QueueBeanLocal {
...
@@ -19,4 +19,9 @@ public interface QueueBeanLocal {
MapReservationQueueEntry
remove
(
EventMap
map
,
EventUser
user
);
MapReservationQueueEntry
remove
(
EventMap
map
,
EventUser
user
);
int
getMinimumSlotsInQueue
();
void
setMinimumSlotsInQueue
(
int
minimumSlotsInQueue
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/MenuBean.java
View file @
9a45c80
...
@@ -142,6 +142,7 @@ public class MenuBean implements MenuBeanLocal {
...
@@ -142,6 +142,7 @@ public class MenuBean implements MenuBeanLocal {
userkauppa
.
setKey
(
"topnavi.usershop"
);
userkauppa
.
setKey
(
"topnavi.usershop"
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/shop/createBill"
),
BillPermission
.
CREATE_BILL
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/shop/createBill"
),
BillPermission
.
CREATE_BILL
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/neomap/reserve"
),
MapPermission
.
BUY_PLACES
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/neomap/reserve"
),
MapPermission
.
BUY_PLACES
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/neomap/notenoughslots"
),
UserPermission
.
ANYUSER
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/foodwave/list"
),
ShopPermission
.
SHOP_FOODWAVE
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/foodwave/list"
),
ShopPermission
.
SHOP_FOODWAVE
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/foodwave/listProducts"
),
ShopPermission
.
SHOP_FOODWAVE
).
setVisible
(
false
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/foodwave/listProducts"
),
ShopPermission
.
SHOP_FOODWAVE
).
setVisible
(
false
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/foodwave/ThanksForOrderingFromCounter"
),
ShopPermission
.
SHOP_FOODWAVE
).
setVisible
(
false
);
userkauppa
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/foodwave/ThanksForOrderingFromCounter"
),
ShopPermission
.
SHOP_FOODWAVE
).
setVisible
(
false
);
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/QueueBean.java
View file @
9a45c80
...
@@ -46,8 +46,9 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -46,8 +46,9 @@ public class QueueBean implements QueueBeanLocal {
}
}
private
final
Map
<
Integer
,
MapQueue
>
mapqueues
;
private
final
Map
<
Integer
,
MapQueue
>
mapqueues
;
private
int
defaultTimeoutMin
=
15
;
private
int
reservingSize
=
1
;
private
int
minimumSlotsInQueue
=
15
;
private
int
reservingSize
=
5
;
private
class
MapQueue
{
private
class
MapQueue
{
// private final Set<MapReservationQueueEntry> reserving = new HashSet<>();
// private final Set<MapReservationQueueEntry> reserving = new HashSet<>();
...
@@ -65,13 +66,15 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -65,13 +66,15 @@ public class QueueBean implements QueueBeanLocal {
// }
// }
private
void
timeoutEntries
()
{
private
void
timeoutEntries
()
{
logger
.
info
(
"Timeouting entries"
);
// give 10 seconds mercy ( and give us some time to go through all entries)
// give 10 seconds mercy ( and give us some time to go through all entries)
Date
now
=
new
Date
(
System
.
currentTimeMillis
()
+
1000
*
15
);
Date
now
=
new
Date
(
System
.
currentTimeMillis
()
+
1000
*
15
);
for
(
EventUser
r
:
reserving
)
{
for
(
EventUser
r
:
reserving
)
{
MapReservationQueueEntry
entry
=
queEntries
.
get
(
r
);
MapReservationQueueEntry
entry
=
queEntries
.
get
(
r
);
logger
.
info
(
"Checking if should remove user from queue {}, timeout {}"
,
r
,
entry
.
getReservationTimeout
());
if
(
entry
.
getReservationTimeout
()
==
null
||
now
.
after
(
entry
.
getReservationTimeout
()))
{
if
(
entry
.
getReservationTimeout
()
==
null
||
now
.
after
(
entry
.
getReservationTimeout
()))
{
this
.
remove
(
entry
.
getUser
());
logger
.
info
(
"Removing Eventuser {} from reserving queue due to reservationTimeout: {}"
,
r
,
entry
.
getReservationTimeout
());
this
.
remove
(
r
);
}
}
}
}
...
@@ -110,6 +113,8 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -110,6 +113,8 @@ public class QueueBean implements QueueBeanLocal {
EventUser
queEntry
=
queue
.
poll
();
EventUser
queEntry
=
queue
.
poll
();
if
(
queEntry
!=
null
)
{
if
(
queEntry
!=
null
)
{
reserving
.
add
(
queEntry
);
reserving
.
add
(
queEntry
);
MapReservationQueueEntry
ue
=
queEntries
.
get
(
queEntry
);
ue
.
setReservationTimeout
(
new
Date
(
System
.
currentTimeMillis
()
+
defaultTimeoutMin
*
60
*
1000
));
}
}
}
}
}
}
...
@@ -118,7 +123,11 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -118,7 +123,11 @@ public class QueueBean implements QueueBeanLocal {
public
MapReservationQueueEntry
remove
(
EventUser
user
)
public
MapReservationQueueEntry
remove
(
EventUser
user
)
{
{
if
(
user
!=
null
)
{
return
null
;
}
MapReservationQueueEntry
ret
=
null
;
MapReservationQueueEntry
ret
=
null
;
synchronized
(
queue
)
{
synchronized
(
queue
)
{
if
(
reserving
.
remove
(
user
))
{
if
(
reserving
.
remove
(
user
))
{
logger
.
info
(
"Removed user {} from reserving queue"
,
user
);
logger
.
info
(
"Removed user {} from reserving queue"
,
user
);
...
@@ -233,7 +242,7 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -233,7 +242,7 @@ public class QueueBean implements QueueBeanLocal {
// DO housekeeping every 10 seconds.
// DO housekeeping every 10 seconds.
nextReservingTimeoutCheck
.
compareAndSet
(
oldTime
,
System
.
currentTimeMillis
()
+
1000
*
10
);
nextReservingTimeoutCheck
.
compareAndSet
(
oldTime
,
System
.
currentTimeMillis
()
+
1000
*
10
);
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
logger
.
warn
(
"Exception while checking reservingTimeouts"
);
logger
.
warn
(
"Exception while checking reservingTimeouts"
,
t
);
}
}
}
}
...
@@ -289,7 +298,7 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -289,7 +298,7 @@ public class QueueBean implements QueueBeanLocal {
}
else
{
}
else
{
List
<
PlaceSlot
>
slots
=
slotfacade
.
findFreePlaceSlotsForProduct
(
user
,
null
);
List
<
PlaceSlot
>
slots
=
slotfacade
.
findFreePlaceSlotsForProduct
(
user
,
null
);
logger
.
info
(
"User {} not yet in queue. User has {} slots"
,
user
,
slots
.
size
());
logger
.
info
(
"User {} not yet in queue. User has {} slots"
,
user
,
slots
.
size
());
if
(!
slots
.
isEmpty
())
{
if
(!
slots
.
isEmpty
()
&&
slots
.
size
()
>=
getMinimumSlotsInQueue
()
)
{
ret
=
queue
.
enter
(
user
);
ret
=
queue
.
enter
(
user
);
logger
.
info
(
"Entered queue: {}"
,
ret
);
logger
.
info
(
"Entered queue: {}"
,
ret
);
}
}
...
@@ -298,6 +307,14 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -298,6 +307,14 @@ public class QueueBean implements QueueBeanLocal {
}
}
@Override
public
int
getMinimumSlotsInQueue
()
{
return
minimumSlotsInQueue
;
}
@Override
public
void
setMinimumSlotsInQueue
(
int
minimumSlotsInQueue
)
{
this
.
minimumSlotsInQueue
=
minimumSlotsInQueue
;
}
}
}
code/moya-web/WebContent/neomap/notenoughslots.xhtml
0 → 100644
View file @
9a45c80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:map=
"http://java.sun.com/jsf/composite/cditools/map"
xmlns:tools=
"http://java.sun.com/jsf/composite/cditools"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:p=
"http://primefaces.org/ui"
>
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<ui:define
name=
"content"
>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/map/AjaxMapView.java
View file @
9a45c80
...
@@ -95,6 +95,9 @@ public class AjaxMapView extends GenericCDIView {
...
@@ -95,6 +95,9 @@ public class AjaxMapView extends GenericCDIView {
map
=
null
;
map
=
null
;
super
.
navihandler
.
forward
(
"/shop/createBill?faces-redirect=true"
);
super
.
navihandler
.
forward
(
"/shop/createBill?faces-redirect=true"
);
}
else
if
(
usersPlaceslots
.
size
()
<
quebean
.
getMinimumSlotsInQueue
())
{
map
=
null
;
super
.
navihandler
.
forward
(
"/neomap/notenoughslots?faces-redirect=true"
);
}
else
{
}
else
{
quebean
.
enterQueue
(
map
,
u
);
quebean
.
enterQueue
(
map
,
u
);
countPlaceslots
(
usersPlaceslots
);
countPlaceslots
(
usersPlaceslots
);
...
@@ -290,5 +293,4 @@ public class AjaxMapView extends GenericCDIView {
...
@@ -290,5 +293,4 @@ public class AjaxMapView extends GenericCDIView {
this
.
slotcount
=
slotcount
;
this
.
slotcount
=
slotcount
;
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment