@@ -305,41 +305,47 @@ private void reserve(NodeStatus status, Slot slot) {
305
305
public void setSession (SlotId slotId , Session session ) {
306
306
Require .nonNull ("Slot ID" , slotId );
307
307
308
- AvailabilityAndNode node = findNode (slotId .getOwningNodeId ());
309
- if (node == null ) {
310
- LOG .warning ("Grid model and reality have diverged. Unable to find node " + slotId .getOwningNodeId ());
311
- return ;
312
- }
308
+ Lock writeLock = lock .writeLock ();
309
+ writeLock .lock ();
310
+ try {
311
+ AvailabilityAndNode node = findNode (slotId .getOwningNodeId ());
312
+ if (node == null ) {
313
+ LOG .warning ("Grid model and reality have diverged. Unable to find node " + slotId .getOwningNodeId ());
314
+ return ;
315
+ }
313
316
314
- Optional <Slot > maybeSlot = node .status .getSlots ().stream ()
315
- .filter (slot -> slotId .equals (slot .getId ()))
316
- .findFirst ();
317
+ Optional <Slot > maybeSlot = node .status .getSlots ().stream ()
318
+ .filter (slot -> slotId .equals (slot .getId ()))
319
+ .findFirst ();
317
320
318
- if (!maybeSlot .isPresent ()) {
319
- LOG .warning ("Grid model and reality have diverged. Unable to find slot " + slotId );
320
- return ;
321
- }
321
+ if (!maybeSlot .isPresent ()) {
322
+ LOG .warning ("Grid model and reality have diverged. Unable to find slot " + slotId );
323
+ return ;
324
+ }
322
325
323
- Slot slot = maybeSlot .get ();
324
- Optional <Session > maybeSession = slot .getSession ();
325
- if (!maybeSession .isPresent ()) {
326
- LOG .warning ("Grid model and reality have diverged. Slot is not reserved. " + slotId );
327
- return ;
328
- }
326
+ Slot slot = maybeSlot .get ();
327
+ Optional <Session > maybeSession = slot .getSession ();
328
+ if (!maybeSession .isPresent ()) {
329
+ LOG .warning ("Grid model and reality have diverged. Slot is not reserved. " + slotId );
330
+ return ;
331
+ }
329
332
330
- Session current = maybeSession .get ();
331
- if (!RESERVED .equals (current .getId ())) {
332
- LOG .warning ("Gid model and reality have diverged. Slot has session and is not reserved. " + slotId );
333
- return ;
334
- }
333
+ Session current = maybeSession .get ();
334
+ if (!RESERVED .equals (current .getId ())) {
335
+ LOG .warning ("Grid model and reality have diverged. Slot has session and is not reserved. " + slotId );
336
+ return ;
337
+ }
335
338
336
- Slot updated = new Slot (
337
- slot .getId (),
338
- slot .getStereotype (),
339
- session == null ? slot .getLastStarted () : session .getStartTime (),
340
- Optional .ofNullable (session ));
339
+ Slot updated = new Slot (
340
+ slot .getId (),
341
+ slot .getStereotype (),
342
+ session == null ? slot .getLastStarted () : session .getStartTime (),
343
+ Optional .ofNullable (session ));
341
344
342
- amend (node .availability , node .status , updated );
345
+ amend (node .availability , node .status , updated );
346
+ } finally {
347
+ writeLock .unlock ();
348
+ }
343
349
}
344
350
345
351
private void amend (Availability availability , NodeStatus status , Slot slot ) {
0 commit comments