Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Pedro J Sanchez
/
simulaeventos
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
10d3eada
authored
Mar 27, 2020
by
Pedro J Sanchez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Upload New File
parent
96be4d08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
src/main/java/es/uja/cursojee/simulaeventos/Registro.java
src/main/java/es/uja/cursojee/simulaeventos/Registro.java
0 → 100644
View file @
10d3eada
package
es
.
uja
.
cursojee
.
simulaeventos
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
public
class
Registro
{
private
final
Evento
evento
;
private
final
List
<
Usuario
>
listaAsistentes
;
private
final
List
<
Usuario
>
listaEspera
;
private
final
Lock
exm
;
// Constantes
private
final
int
PRIMERO
=
0
;
public
Registro
(
Evento
evento
)
{
super
();
this
.
evento
=
evento
;
this
.
listaAsistentes
=
new
ArrayList
();
this
.
listaEspera
=
new
ArrayList
();
this
.
exm
=
new
ReentrantLock
();
}
public
Evento
getEvento
()
{
return
evento
;
}
public
boolean
addAsistente
(
Usuario
asistente
)
{
boolean
resultado
=
false
;
// Protocolo entrada exm
exm
.
lock
();
try
{
// Sección crítica
if
(
listaAsistentes
.
size
()
<
evento
.
getAforo
()
)
{
listaAsistentes
.
add
(
asistente
);
resultado
=
true
;
}
else
{
listaEspera
.
add
(
asistente
);
}
}
finally
{
// Protocolo salida exm
exm
.
unlock
();
}
return
resultado
;
}
public
boolean
removeAsistente
(
Usuario
asistente
)
{
boolean
resultado
=
false
;
// Protocolo entrada exm
exm
.
lock
();
try
{
// Sección crítica exm
if
(
listaAsistentes
.
remove
(
asistente
)
)
{
if
(
!
listaEspera
.
isEmpty
()
)
{
Usuario
espera
=
listaEspera
.
remove
(
PRIMERO
);
listaAsistentes
.
add
(
espera
);
}
resultado
=
true
;
}
}
finally
{
// Protoco salida exm
exm
.
unlock
();
}
return
resultado
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment