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; }
private void fireUsageEvent( final OwnerFullName ownerFullName, final Supplier<EventActionInfo<AddressAction>> actionInfoSupplier) { if (!Principals.isFakeIdentityAccountNumber(ownerFullName.getAccountNumber())) { try { ListenerRegistry.getInstance() .fireEvent( AddressEvent.with( getNaturalId(), getDisplayName(), ownerFullName, Accounts.lookupAccountById(ownerFullName.getAccountNumber()).getName(), actionInfoSupplier.get())); } catch (final Exception e) { LOG.error(e, e); } } }
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; }