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 89e58f87
authored
Dec 14, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queue mgmt
1 parent
831114ff
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
274 additions
and
2 deletions
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/QueueBeanLocal.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/QueueBean.java
code/moya-web/WebContent/neomap/quemgmt.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/map/QueueManageView.java
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/QueueBeanLocal.java
View file @
89e58f8
package
fi
.
codecrew
.
moya
.
beans
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
javax.ejb.Local
;
import
fi.codecrew.moya.model.EventMap
;
...
...
@@ -23,5 +28,26 @@ public interface QueueBeanLocal {
void
setMinimumSlotsInQueue
(
int
minimumSlotsInQueue
);
Date
getReservationTimeout
(
EventMap
map
,
EventUser
user
);
void
setReservingSize
(
int
reservingSize
);
int
getReservingSize
();
void
setDefaultTimeoutMin
(
int
defaultTimeoutMin
);
int
getDefaultTimeoutMin
();
MapQueueI
getMapQueue
(
EventMap
map
);
public
interface
MapQueueI
{
LinkedBlockingQueue
<
EventUser
>
getQueue
();
Set
<
EventUser
>
getReserving
();
MapReservationQueueEntry
getEntry
(
EventUser
u
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/QueueBean.java
View file @
89e58f8
...
...
@@ -11,6 +11,8 @@ import java.util.concurrent.ConcurrentMap;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.atomic.AtomicLong
;
import
javax.annotation.security.DeclareRoles
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ejb.Asynchronous
;
import
javax.ejb.EJB
;
import
javax.ejb.LocalBean
;
...
...
@@ -21,6 +23,8 @@ import javax.ejb.Singleton;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.enums.apps.MapPermission
;
import
fi.codecrew.moya.enums.apps.UserPermission
;
import
fi.codecrew.moya.facade.PlaceSlotFacade
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.EventUser
;
...
...
@@ -34,6 +38,8 @@ import fi.codecrew.moya.model.map.MapReservationQueueEntry;
*/
@Singleton
@LocalBean
@Lock
(
LockType
.
READ
)
@DeclareRoles
({
MapPermission
.
S_MANAGE_MAPS
})
public
class
QueueBean
implements
QueueBeanLocal
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
QueueBean
.
class
);
...
...
@@ -46,11 +52,11 @@ public class QueueBean implements QueueBeanLocal {
}
private
final
Map
<
Integer
,
MapQueue
>
mapqueues
;
private
int
defaultTimeoutMin
=
1
5
;
private
int
defaultTimeoutMin
=
1
0
;
private
int
minimumSlotsInQueue
=
15
;
private
int
reservingSize
=
5
;
private
class
MapQueue
{
private
class
MapQueue
implements
MapQueueI
{
// private final Set<MapReservationQueueEntry> reserving = new HashSet<>();
private
final
Set
<
EventUser
>
reserving
=
Collections
.
newSetFromMap
(
new
ConcurrentHashMap
<
EventUser
,
Boolean
>());
private
final
LinkedBlockingQueue
<
EventUser
>
queue
=
new
LinkedBlockingQueue
<>();
...
...
@@ -148,6 +154,8 @@ public class QueueBean implements QueueBeanLocal {
if
(!
reserving
.
contains
(
user
)
&&
!
queue
.
contains
(
user
))
{
ret
=
new
MapReservationQueueEntry
();
ret
.
setUser
(
user
);
ret
.
setSeenTime
(
new
Date
());
queEntries
.
put
(
user
,
ret
);
boolean
queStat
=
queue
.
offer
(
user
);
logger
.
info
(
"User {} not in queue, offer state {}"
,
user
,
queStat
);
...
...
@@ -194,6 +202,14 @@ public class QueueBean implements QueueBeanLocal {
public
MapReservationQueueEntry
getEntry
(
EventUser
user
)
{
return
queEntries
.
get
(
user
);
}
public
LinkedBlockingQueue
<
EventUser
>
getQueue
()
{
return
queue
;
}
public
Set
<
EventUser
>
getReserving
()
{
return
reserving
;
}
}
@EJB
...
...
@@ -230,6 +246,7 @@ public class QueueBean implements QueueBeanLocal {
}
@Lock
(
LockType
.
READ
)
@Asynchronous
private
void
checkReservingTimeouts
()
{
try
{
...
...
@@ -245,6 +262,7 @@ public class QueueBean implements QueueBeanLocal {
}
}
@Lock
(
LockType
.
READ
)
private
MapQueue
getMapque
(
EventMap
map
)
{
if
(
map
==
null
)
{
return
null
;
...
...
@@ -264,6 +282,17 @@ public class QueueBean implements QueueBeanLocal {
@Lock
(
LockType
.
READ
)
@Override
public
Date
getReservationTimeout
(
EventMap
map
,
EventUser
user
)
{
Date
d
=
null
;
MapReservationQueueEntry
ret
=
getMapque
(
map
).
getEntry
(
user
);
if
(
ret
!=
null
)
d
=
ret
.
getReservationTimeout
();
return
d
;
}
@Lock
(
LockType
.
READ
)
@Override
public
Integer
getQueuePosition
(
EventMap
map
,
EventUser
user
)
{
return
getMapque
(
map
).
getPosition
(
user
);
...
...
@@ -307,13 +336,45 @@ public class QueueBean implements QueueBeanLocal {
}
@Override
@Lock
(
LockType
.
READ
)
public
int
getMinimumSlotsInQueue
()
{
return
minimumSlotsInQueue
;
}
@Override
@Lock
(
LockType
.
READ
)
@RolesAllowed
(
MapPermission
.
S_MANAGE_MAPS
)
public
void
setMinimumSlotsInQueue
(
int
minimumSlotsInQueue
)
{
this
.
minimumSlotsInQueue
=
minimumSlotsInQueue
;
}
@Lock
(
LockType
.
READ
)
@RolesAllowed
(
MapPermission
.
S_MANAGE_MAPS
)
@Override
public
MapQueue
getMapQueue
(
EventMap
map
)
{
return
getMapque
(
map
);
}
@Override
public
int
getDefaultTimeoutMin
()
{
return
defaultTimeoutMin
;
}
@Override
public
void
setDefaultTimeoutMin
(
int
defaultTimeoutMin
)
{
this
.
defaultTimeoutMin
=
defaultTimeoutMin
;
}
@Override
public
int
getReservingSize
()
{
return
reservingSize
;
}
@Override
@RolesAllowed
(
MapPermission
.
S_MANAGE_MAPS
)
public
void
setReservingSize
(
int
reservingSize
)
{
this
.
reservingSize
=
reservingSize
;
}
}
code/moya-web/WebContent/neomap/quemgmt.xhtml
0 → 100644
View file @
89e58f8
<!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}"
>
<f:metadata>
<f:viewParam
name=
"mapId"
value=
"#{queueManageView.mapId}"
/>
<f:event
type=
"preRenderView"
listener=
"#{queueManageView.initView}"
/>
</f:metadata>
<ui:define
name=
"content"
>
<h:form>
<p:panelGrid
columns=
"1"
>
<p:inputText
id=
"minslots"
label=
"#{i18n['queuemgmt.minimumSlotsInQueue']}"
value=
"#{queueManageView.queuebean.minimumSlotsInQueue}"
/>
<p:inputText
id=
"reservingsize"
label=
"#{i18n['queuemgmt.reservingSize']}"
value=
"#{queueManageView.queuebean.reservingSize}"
/>
<p:inputText
id=
"defaultTimeout"
label=
"#{i18n['queuemgmt.defaultTimeoutMin']}"
value=
"#{queueManageView.queuebean.defaultTimeoutMin}"
/>
</p:panelGrid>
<p:commandButton
ajax=
"false"
></p:commandButton>
</h:form>
<h2>
Currently reserving
</h2>
<p:dataTable
var=
"u"
value=
"#{queueManageView.userReserving}"
>
<p:column>
<h:outputText
value=
"#{u.user.user.nick}"
/>
</p:column>
<p:column
headerText=
"Created"
>
<h:outputText
value=
"#{u.created}"
>
<f:convertDateTime
pattern=
"#{sessionHandler.datetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
/>
</h:outputText>
</p:column>
<p:column
headerText=
"Reservation timeout"
>
<p:calendar
value=
"#{u.seenTime}"
pattern=
"#{sessionHandler.datetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
showOn=
"button"
/>
<h:outputText
value=
"#{u.reservationTimeout}"
>
<f:convertDateTime
pattern=
"#{sessionHandler.datetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
/>
</h:outputText>
</p:column>
</p:dataTable>
<h2>
In queue
</h2>
<p:dataTable
var=
"u"
value=
"#{queueManageView.userQueue}"
>
<p:column>
<h:outputText
value=
"#{u.user.user.nick}"
/>
</p:column>
<p:column
headerText=
"Created"
>
<h:outputText
value=
"#{u.created}"
>
<f:convertDateTime
pattern=
"#{sessionHandler.datetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
/>
</h:outputText>
</p:column>
<p:column
headerText=
"Seen time"
>
<p:calendar
value=
"#{u.seenTime}"
pattern=
"#{sessionHandler.datetimeFormat}"
timeZone=
"#{sessionHandler.timezone}"
showOn=
"button"
/>
</p:column>
</p:dataTable>
</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/QueueManageView.java
0 → 100644
View file @
89e58f8
package
fi
.
codecrew
.
moya
.
web
.
cdiview
.
map
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.enterprise.context.RequestScoped
;
import
javax.faces.model.ListDataModel
;
import
javax.inject.Named
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.beans.PlaceBeanLocal
;
import
fi.codecrew.moya.beans.QueueBeanLocal
;
import
fi.codecrew.moya.beans.QueueBeanLocal.MapQueueI
;
import
fi.codecrew.moya.enums.apps.MapPermission
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.map.MapReservationQueueEntry
;
import
fi.codecrew.moya.web.cdiview.GenericCDIView
;
@Named
@ConversationScoped
public
class
QueueManageView
extends
GenericCDIView
{
private
static
final
long
serialVersionUID
=
-
8298859537580380999L
;
private
Integer
mapId
;
@EJB
private
PlaceBeanLocal
placebean
;
@EJB
private
QueueBeanLocal
quebean
;
private
EventMap
map
;
private
MapQueueI
queue
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
QueueManageView
.
class
);
public
void
initView
()
{
if
(
super
.
requirePermissions
(
MapPermission
.
MANAGE_MAPS
)
&&
map
==
null
)
{
map
=
placebean
.
findMap
(
mapId
);
queue
=
quebean
.
getMapQueue
(
map
);
logger
.
info
(
"Got queue {} for map {} with id {} to manage"
,
queue
,
map
,
mapId
);
super
.
beginConversation
();
}
}
public
ListDataModel
<
MapReservationQueueEntry
>
getUserQueue
()
{
List
<
MapReservationQueueEntry
>
ret
=
new
ArrayList
<>();
if
(
queue
==
null
)
return
null
;
for
(
EventUser
u
:
queue
.
getQueue
())
{
ret
.
add
(
queue
.
getEntry
(
u
));
}
return
new
ListDataModel
<>(
ret
);
}
public
ListDataModel
<
MapReservationQueueEntry
>
getUserReserving
()
{
List
<
MapReservationQueueEntry
>
ret
=
new
ArrayList
<>();
if
(
queue
==
null
)
return
null
;
for
(
EventUser
u
:
queue
.
getReserving
())
{
ret
.
add
(
queue
.
getEntry
(
u
));
}
return
new
ListDataModel
<>(
ret
);
}
public
EventMap
getMap
()
{
return
map
;
}
public
void
setMap
(
EventMap
map
)
{
this
.
map
=
map
;
}
public
Integer
getMapId
()
{
return
mapId
;
}
public
void
setMapId
(
Integer
mapId
)
{
this
.
mapId
=
mapId
;
}
public
MapQueueI
getQueue
()
{
return
queue
;
}
public
void
setQueue
(
MapQueueI
queue
)
{
this
.
queue
=
queue
;
}
public
QueueBeanLocal
getQueuebean
()
{
return
quebean
;
}
}
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