Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Lucia Montero Navarro
/
MonteroNavarroLuciaPrac1
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
9cd448de
authored
Mar 29, 2020
by
Lucia Montero Navarro
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
v0.1 Implementación Práctica 1
parent
3ce71c2e
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
520 additions
and
1 deletions
src/main/java/com/daw/monteronavarroluciaprac1/Constantes.java
src/main/java/com/daw/monteronavarroluciaprac1/Escena.java
src/main/java/com/daw/monteronavarroluciaprac1/Finalizador.java
src/main/java/com/daw/monteronavarroluciaprac1/Fotograma.java
src/main/java/com/daw/monteronavarroluciaprac1/GeneradorEscena.java
src/main/java/com/daw/monteronavarroluciaprac1/Practica1.java
src/main/java/com/daw/monteronavarroluciaprac1/RenderizadorEscenas.java
src/main/java/com/daw/monteronavarroluciaprac1/Constantes.java
0 → 100644
View file @
9cd448de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
java.util.Random
;
/**
* Constantes, tipo enumerado y generador de numeros aleatorios necesarios para
* la ejecucion de la aplicacion
* @author fconde
*/
public
class
Constantes
{
// - Generador de numeros aleatorio ----------------------------------------
public
static
final
Random
aleatorio
=
new
Random
();
// - Tipo enumerado --------------------------------------------------------
public
enum
Prioridad
{
BAJA
(
0
),
ALTA
(
1
);
private
final
int
valor
;
private
Prioridad
(
int
valor
)
{
this
.
valor
=
valor
;
}
public
static
Prioridad
getPrioridadAleatoria
()
{
int
valorAleatorio
=
aleatorio
.
nextInt
(
MAX_VALOR_PRIORIDAD
);
return
Prioridad
.
values
()[
valorAleatorio
];
}
}
// - Constantes ------------------------------------------------------------
public
static
final
int
MAX_VALOR_PRIORIDAD
=
2
;
public
static
final
int
VARIACION_TIEMPO
=
2
;
public
static
final
int
MIN_TIEMPO_FOTOGRAMA
=
2
;
public
static
final
int
TIEMPO_FINALIZACION_ESCENA
=
2
;
public
static
final
int
MIN_NUM_FOTOGRAMAS
=
3
;
public
static
final
int
VARIACION_NUM_FOTOGRAMAS
=
3
;
public
static
final
int
MIN_NUM_ESCENAS
=
3
;
public
static
final
int
VARIACION_NUM_ESCENAS
=
3
;
public
static
final
int
MIN_TIEMPO_GENERACION
=
3
;
public
static
final
int
NUM_GENERADORES
=
4
;
public
static
final
int
NUM_RENDERIZADORES
=
3
;
public
static
final
int
MAX_ESCENAS_EN_ESPERA
=
4
;
}
\ No newline at end of file
src/main/java/com/daw/monteronavarroluciaprac1/Escena.java
0 → 100644
View file @
9cd448de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
MIN_NUM_FOTOGRAMAS
;
import
com.daw.monteronavarroluciaprac1.Constantes.Prioridad
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
TIEMPO_FINALIZACION_ESCENA
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
VARIACION_NUM_FOTOGRAMAS
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
aleatorio
;
import
java.sql.Time
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.List
;
/**
*
* @author LucíaM
*/
public
class
Escena
{
private
Prioridad
prioridad
;
private
String
id
;
private
int
duracion
;
private
List
<
Fotograma
>
listaFotogramas
;
private
Calendar
horaGeneracion
;
private
Calendar
horaInicioProcesamiento
;
private
Calendar
horaFinProcesamiento
;
private
Fotograma
f
;
public
Escena
(
String
id
,
Prioridad
prioridad
,
int
duracion
,
List
<
Fotograma
>
listaFotogramas
){
this
.
id
=
id
;
this
.
listaFotogramas
=
new
ArrayList
();
this
.
duracion
=
TIEMPO_FINALIZACION_ESCENA
;
this
.
prioridad
=
Prioridad
.
getPrioridadAleatoria
();
}
public
Escena
(){
//horaGeneracion= LocalDateTime.now();
int
numFotogramasAGenerar
;
Fotograma
fotograma
;
numFotogramasAGenerar
=
aleatorio
.
nextInt
(
MIN_NUM_FOTOGRAMAS
)+
aleatorio
.
nextInt
(
VARIACION_NUM_FOTOGRAMAS
+
MIN_NUM_FOTOGRAMAS
);
while
(
numFotogramasAGenerar
==
0
){
f
.
crearFotograma
();
listaFotogramas
.
add
(
f
);
duracion
=
duracion
+
f
.
getDuracion
();
}
}
/**
* @return the prioridad
*/
public
Prioridad
getPrioridad
()
{
return
prioridad
;
}
/**
* @param prioridad the prioridad to set
*/
public
void
setPrioridad
(
Prioridad
prioridad
)
{
this
.
prioridad
=
prioridad
;
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the duracion
*/
public
int
getDuracion
()
{
return
duracion
;
}
/**
* @param duracion the duracion to set
*/
public
void
setDuracion
(
int
duracion
)
{
this
.
duracion
=
duracion
;
}
/**
* @return the horaGeneracion
*/
public
Calendar
getHoraGeneracion
()
{
return
horaGeneracion
;
}
/**
* @param horaGeneracion the horaGeneracion to set
*/
public
void
setHoraGeneracion
(
Calendar
horaGeneracion
)
{
this
.
horaGeneracion
=
horaGeneracion
;
}
/**
* @return the horaInicioProcesamiento
*/
public
Calendar
getHoraInicioProcesamiento
()
{
return
horaInicioProcesamiento
;
}
/**
* @param horaInicioProcesamiento the horaInicioProcesamiento to set
*/
public
void
setHoraInicioProcesamiento
(
Calendar
horaInicioProcesamiento
)
{
this
.
horaInicioProcesamiento
=
horaInicioProcesamiento
;
}
/**
* @return the horaFinProcesamiento
*/
public
Calendar
getHoraFinProcesamiento
()
{
return
horaFinProcesamiento
;
}
/**
* @param horaFinProcesamiento the horaFinProcesamiento to set
*/
public
void
setHoraFinProcesamiento
(
Calendar
horaFinProcesamiento
)
{
this
.
horaFinProcesamiento
=
horaFinProcesamiento
;
}
/**
* @return the listaFotogramas
*/
public
List
<
Fotograma
>
getListaFotogramas
()
{
return
listaFotogramas
;
}
/**
* @param listaFotogramas the listaFotogramas to set
*/
public
void
setListaFotogramas
(
List
<
Fotograma
>
listaFotogramas
)
{
this
.
listaFotogramas
=
listaFotogramas
;
}
}
src/main/java/com/daw/monteronavarroluciaprac1/Finalizador.java
0 → 100644
View file @
9cd448de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
java.util.List
;
/**
*
* @author LucíaM
*/
public
class
Finalizador
{
private
List
<
RenderizadorEscenas
>
ListaRenderizadores
;
// public ejecucion(){
// for ()
//}
/**
* @return the ListaRenderizadores
*/
public
List
<
RenderizadorEscenas
>
getListaRenderizadores
()
{
return
ListaRenderizadores
;
}
/**
* @param ListaRenderizadores the ListaRenderizadores to set
*/
public
void
setListaRenderizadores
(
List
<
RenderizadorEscenas
>
ListaRenderizadores
)
{
this
.
ListaRenderizadores
=
ListaRenderizadores
;
}
}
src/main/java/com/daw/monteronavarroluciaprac1/Fotograma.java
0 → 100644
View file @
9cd448de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
MIN_TIEMPO_FOTOGRAMA
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
VARIACION_TIEMPO
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
aleatorio
;
/**
*
* @author LucíaM
*/
public
class
Fotograma
{
private
String
id
;
private
int
duracion
;
private
Fotograma
(){
this
.
id
=
id
;
duracion
=
aleatorio
.
nextInt
(
MIN_TIEMPO_FOTOGRAMA
)+
aleatorio
.
nextInt
(
MIN_TIEMPO_FOTOGRAMA
+
VARIACION_TIEMPO
);
}
public
void
crearFotograma
(){
this
.
id
=
id
;
duracion
=
aleatorio
.
nextInt
(
MIN_TIEMPO_FOTOGRAMA
)+
aleatorio
.
nextInt
(
MIN_TIEMPO_FOTOGRAMA
+
VARIACION_TIEMPO
);
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the duracion
*/
public
int
getDuracion
()
{
return
duracion
;
}
/**
* @param duracion the duracion to set
*/
public
void
setDuracion
(
int
duracion
)
{
this
.
duracion
=
duracion
;
}
}
src/main/java/com/daw/monteronavarroluciaprac1/GeneradorEscena.java
0 → 100644
View file @
9cd448de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
MIN_NUM_ESCENAS
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
MIN_TIEMPO_GENERACION
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
Prioridad
.
ALTA
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
Prioridad
.
BAJA
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
VARIACION_NUM_ESCENAS
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
VARIACION_TIEMPO
;
import
static
com
.
daw
.
monteronavarroluciaprac1
.
Constantes
.
aleatorio
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.Semaphore
;
import
java.util.stream.DoubleStream
;
/**
*
* @author LucíaM
*/
public
class
GeneradorEscena
{
private
String
id
;
private
final
Semaphore
fillSemAltaPrioridad
;
private
final
Semaphore
mutexAltaPrioridad
;
private
final
Semaphore
fillSemBajaPrioridad
;
private
final
Semaphore
mutexBajaPrioridad
;
private
final
Semaphore
emptySemBajaPrioridad
;
public
GeneradorEscena
(
int
generadores
){
this
.
id
=
id
;
this
.
fillSemAltaPrioridad
=
new
Semaphore
(
0
);
this
.
mutexAltaPrioridad
=
new
Semaphore
(
0
);
this
.
fillSemBajaPrioridad
=
new
Semaphore
(
0
);
this
.
emptySemBajaPrioridad
=
new
Semaphore
(
0
);
this
.
mutexBajaPrioridad
=
new
Semaphore
(
0
);
}
List
<
Escena
>
ejecucion
()
throws
InterruptedException
{
List
<
Escena
>
listaAltaPrioridad
=
new
ArrayList
();
List
<
Escena
>
listaBajaPrioridad
=
new
ArrayList
();
List
<
Escena
>
resultado
=
new
ArrayList
();
int
numEscenasAGenerar
;
numEscenasAGenerar
=
aleatorio
.
nextInt
(
MIN_NUM_ESCENAS
)+
aleatorio
.
nextInt
(
MIN_NUM_ESCENAS
+
VARIACION_NUM_ESCENAS
);
while
(
numEscenasAGenerar
==
0
){
int
tiempoGeneracionEscena
;
tiempoGeneracionEscena
=
aleatorio
.
nextInt
(
MIN_TIEMPO_GENERACION
)+
aleatorio
.
nextInt
(
MIN_TIEMPO_GENERACION
+
VARIACION_TIEMPO
);
//esperar TiempoGeneracionEscena
Escena
escena
;
escena
=
new
Escena
();
//escena.inicializarEscena();
resultado
.
add
(
escena
);
if
(
escena
.
getPrioridad
()==
ALTA
){
fillSemAltaPrioridad
.
wait
();
mutexAltaPrioridad
.
wait
();
listaAltaPrioridad
.
add
(
escena
);
mutexAltaPrioridad
.
release
();
}
else
{
fillSemBajaPrioridad
.
wait
();
mutexBajaPrioridad
.
wait
();
listaBajaPrioridad
.
add
(
escena
);
mutexBajaPrioridad
.
release
();
emptySemBajaPrioridad
.
release
();
}
}
return
resultado
;
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
private
List
<
Escena
>
newArrayList
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
}
}
src/main/java/com/daw/monteronavarroluciaprac1/Practica1.java
View file @
9cd448de
...
...
@@ -5,10 +5,25 @@
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
java.util.Random
;
/**
*
* @author LucíaM
*/
public
class
Practica1
{
public
class
Practica1
extends
Constantes
{
public
final
static
Random
aleatorio
=
new
Random
();
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
[]
args
)
{
GeneradorEscena
generadores
=
new
GeneradorEscena
(
NUM_GENERADORES
);
RenderizadorEscenas
renderizadores
=
new
RenderizadorEscenas
(
NUM_RENDERIZADORES
);
System
.
out
.
println
(
"** Hilo(PRINCIPAL): Ha iniciado la ejecucion\n"
);
System
.
out
.
println
(
"** Hilo(PRINCIPAL): Ha finalizado la ejecucion"
);
}
}
src/main/java/com/daw/monteronavarroluciaprac1/RenderizadorEscenas.java
0 → 100644
View file @
9cd448de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com
.
daw
.
monteronavarroluciaprac1
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.Semaphore
;
/**
*
* @author LucíaM
*/
public
class
RenderizadorEscenas
{
private
String
id
;
private
boolean
terminadosGeneradores
;
private
final
Semaphore
mainMutex
;
private
final
Semaphore
emptySemAltaPrioridad
;
private
final
Semaphore
mutexAltaPrioridad
;
private
final
Semaphore
mutexBajaPrioridad
;
private
final
Semaphore
fillSemBajaPrioridad
;
private
final
Semaphore
emptySemBajaPrioridad
;
public
RenderizadorEscenas
(
int
numRenderizadores
){
this
.
id
=
id
;
this
.
terminadosGeneradores
=
true
;
this
.
mainMutex
=
new
Semaphore
(
0
);
this
.
emptySemAltaPrioridad
=
new
Semaphore
(
0
);
this
.
mutexAltaPrioridad
=
new
Semaphore
(
0
);
this
.
mutexBajaPrioridad
=
new
Semaphore
(
0
);
this
.
fillSemBajaPrioridad
=
new
Semaphore
(
0
);
this
.
emptySemBajaPrioridad
=
new
Semaphore
(
0
);
}
public
List
<
Escena
>
ejecucion
()
throws
InterruptedException
{
Escena
escena
=
new
Escena
()
;
boolean
tengoEscena
=
true
;
List
<
Escena
>
listaBajaPrioridad
=
new
ArrayList
();
List
<
Escena
>
listaAltaPrioridad
=
new
ArrayList
();
List
<
Escena
>
resultado
=
new
ArrayList
();
boolean
terminadosGeneradores
=
true
;
while
(
tengoEscena
){
tengoEscena
=
false
;
mainMutex
.
wait
();
if
(
listaAltaPrioridad
.
size
()!=
0
){
emptySemAltaPrioridad
.
wait
();
mutexAltaPrioridad
.
wait
();
listaAltaPrioridad
.
remove
(
escena
);
mutexAltaPrioridad
.
release
();
tengoEscena
=
true
;
}
else
if
(
listaBajaPrioridad
.
size
()!=
0
){
emptySemBajaPrioridad
.
wait
();
mutexBajaPrioridad
.
wait
();
listaBajaPrioridad
.
remove
(
escena
);
mutexBajaPrioridad
.
release
();
fillSemBajaPrioridad
.
release
();
tengoEscena
=
true
;
}
else
if
(
terminadosGeneradores
){
mainMutex
.
release
();
return
resultado
;
}
mainMutex
.
release
();
}
return
resultado
;
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the terminadosGeneradores
*/
public
boolean
isTerminadosGeneradores
()
{
return
terminadosGeneradores
;
}
/**
* @param terminadosGeneradores the terminadosGeneradores to set
*/
public
void
setTerminadosGeneradores
(
boolean
terminadosGeneradores
)
{
this
.
terminadosGeneradores
=
true
;
}
}
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