Ejemplo n.º 1
0
 public ExtantNetwork extantNetwork()
     throws NotEnoughResourcesException, TransientEntityException {
   if (!NetworkGroups.networkingConfiguration().hasNetworking()) {
     ExtantNetwork bogusNet = ExtantNetwork.bogus(this);
     if (!this.hasExtantNetwork()) this.setExtantNetwork(bogusNet);
     return bogusNet;
   } else if (!Entities.isPersistent(this)) {
     throw new TransientEntityException(this.toString());
   } else {
     ExtantNetwork exNet = this.getExtantNetwork();
     if (exNet == null) {
       for (Integer i : Numbers.shuffled(NetworkGroups.networkTagInterval())) {
         try {
           Entities.uniqueResult(ExtantNetwork.named(i));
           continue;
         } catch (Exception ex) {
           exNet = ExtantNetwork.create(this, i);
           Entities.persist(exNet);
           this.setExtantNetwork(exNet);
           return this.getExtantNetwork();
         }
       }
       throw new NotEnoughResourcesException(
           "Failed to allocate network tag for network: "
               + this.getFullName()
               + ": no network tags are free.");
     } else {
       return this.getExtantNetwork();
     }
   }
 }