public Address assign(final VmInstance vm) { SplitTransition assign = new SplitTransition(Transition.assigning) { public void top() { Address.this.setInstanceInfo( vm.getInstanceUuid(), vm.getInstanceId(), vm.getPrivateAddress()); Address.this.stateUuid = UUID.randomUUID().toString(); } public void bottom() {} }; if (State.impending.equals(this.atomicState.getReference())) { this.transition(State.impending, State.assigned, true, true, assign); } else { this.transition(State.allocated, State.assigned, false, true, assign); } fireUsageEvent( new Supplier<EventActionInfo<AddressAction>>() { @Override public EventActionInfo<AddressAction> get() { return AddressEvent.forAssociate(vm.getInstanceUuid(), vm.getInstanceId()); } }); return this; }
public Address unassign() { fireUsageEvent( new Supplier<EventActionInfo<AddressAction>>() { @Override public EventActionInfo<AddressAction> get() { return AddressEvent.forDisassociate(instanceUuid, instanceId); } }); SplitTransition unassign = new SplitTransition(Transition.unassigning) { public void top() { try { VmInstance vm = VmInstances.lookup(Address.this.getInstanceId()); } catch (NoSuchElementException e) { LOG.debug(e); } } public void bottom() { Address.this.stateUuid = UUID.randomUUID().toString(); Address.this.instanceUuid = UNASSIGNED_INSTANCEUUID; Address.this.instanceId = UNASSIGNED_INSTANCEID; Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR; } }; if (State.impending.equals(this.atomicState.getReference())) { this.transition(State.impending, State.allocated, this.isPending(), true, unassign); } else { this.transition(State.assigned, State.allocated, false, true, unassign); } return this; }
public Address allocate(final OwnerFullName ownerFullName) { this.transition( State.unallocated, State.allocated, false, true, new SplitTransition(Transition.allocating) { public void top() { Address.this.instanceUuid = UNASSIGNED_INSTANCEUUID; Address.this.instanceId = UNASSIGNED_INSTANCEID; Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR; Address.this.setOwner(ownerFullName); Address.addAddress(Address.this); try { Addresses.getInstance().register(Address.this); } catch (NoSuchElementException e) { LOG.debug(e); } Address.this.stateUuid = UUID.randomUUID().toString(); Address.this.atomicState.attemptMark(State.allocated, false); } public void bottom() {} }); fireUsageEvent(ownerFullName, Suppliers.ofInstance(AddressEvent.forAllocate())); return this; }
public Address release() { fireUsageEvent(Suppliers.ofInstance(AddressEvent.forRelease())); SplitTransition release = new SplitTransition(Transition.unallocating) { public void top() { Address.this.instanceUuid = UNASSIGNED_INSTANCEUUID; Address.this.instanceId = UNASSIGNED_INSTANCEID; Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR; Address.removeAddress(Address.this.getDisplayName()); Address.this.setOwner(Principals.nobodyFullName()); Address.this.stateUuid = UUID.randomUUID().toString(); Address.this.atomicState.attemptMark(State.unallocated, false); } public void bottom() {} }; if (State.impending.equals(this.atomicState.getReference())) { this.transition(State.impending, State.unallocated, this.isPending(), true, release); } else { this.transition(State.allocated, State.unallocated, false, true, release); } return this; }
private void fireUsageEvent(final Supplier<EventActionInfo<AddressAction>> actionInfoSupplier) { fireUsageEvent(getOwner(), actionInfoSupplier); }