コード例 #1
0
 /** Import configuration */
 public void importConfiguration(java.io.InputStream is)
     throws java.io.IOException, ManifoldCFException {
   int version = ManifoldCF.readDword(is);
   if (version != 1)
     throw new java.io.IOException(
         "Unknown repository connection configuration version: " + Integer.toString(version));
   int count = ManifoldCF.readDword(is);
   int i = 0;
   while (i < count) {
     IRepositoryConnection conn = create();
     conn.setName(ManifoldCF.readString(is));
     conn.setDescription(ManifoldCF.readString(is));
     conn.setClassName(ManifoldCF.readString(is));
     conn.getConfigParams().fromXML(ManifoldCF.readString(is));
     conn.setACLAuthority(ManifoldCF.readString(is));
     conn.setMaxConnections(ManifoldCF.readDword(is));
     int throttleCount = ManifoldCF.readDword(is);
     int j = 0;
     while (j < throttleCount) {
       String throttleName = ManifoldCF.readString(is);
       conn.addThrottleValue(throttleName, ManifoldCF.readString(is), ManifoldCF.readfloat(is));
       j++;
     }
     // Attempt to save this connection
     save(conn);
     i++;
   }
 }
コード例 #2
0
 /** Export configuration */
 public void exportConfiguration(java.io.OutputStream os)
     throws java.io.IOException, ManifoldCFException {
   // Write a version indicator
   ManifoldCF.writeDword(os, 1);
   // Get the authority list
   IRepositoryConnection[] list = getAllConnections();
   // Write the number of authorities
   ManifoldCF.writeDword(os, list.length);
   // Loop through the list and write the individual repository connection info
   int i = 0;
   while (i < list.length) {
     IRepositoryConnection conn = list[i++];
     ManifoldCF.writeString(os, conn.getName());
     ManifoldCF.writeString(os, conn.getDescription());
     ManifoldCF.writeString(os, conn.getClassName());
     ManifoldCF.writeString(os, conn.getConfigParams().toXML());
     ManifoldCF.writeString(os, conn.getACLAuthority());
     ManifoldCF.writeDword(os, conn.getMaxConnections());
     String[] throttles = conn.getThrottles();
     ManifoldCF.writeDword(os, throttles.length);
     int j = 0;
     while (j < throttles.length) {
       String throttleName = throttles[j++];
       ManifoldCF.writeString(os, throttleName);
       ManifoldCF.writeString(os, conn.getThrottleDescription(throttleName));
       ManifoldCF.writefloat(os, conn.getThrottleValue(throttleName));
     }
   }
 }
コード例 #3
0
  /**
   * Save a repository connection object.
   *
   * @param object is the object to save.
   * @return true if the object was created, false otherwise.
   */
  public boolean save(IRepositoryConnection object) throws ManifoldCFException {
    StringSetBuffer ssb = new StringSetBuffer();
    ssb.add(getRepositoryConnectionsKey());
    ssb.add(getRepositoryConnectionKey(object.getName()));
    StringSet cacheKeys = new StringSet(ssb);
    while (true) {
      // Catch deadlock condition
      long sleepAmt = 0L;
      try {
        ICacheHandle ch = cacheManager.enterCache(null, cacheKeys, getTransactionID());
        try {
          beginTransaction();
          try {
            // performLock();
            // Notify of a change to the configuration
            ManifoldCF.noteConfigurationChange();
            boolean isNew = object.getIsNew();
            // See whether the instance exists
            ArrayList params = new ArrayList();
            String query =
                buildConjunctionClause(
                    params,
                    new ClauseDescription[] {new UnitaryClause(nameField, object.getName())});
            IResultSet set =
                performQuery(
                    "SELECT * FROM " + getTableName() + " WHERE " + query + " FOR UPDATE",
                    params,
                    null,
                    null);
            HashMap values = new HashMap();
            values.put(descriptionField, object.getDescription());
            values.put(classNameField, object.getClassName());
            values.put(groupNameField, object.getACLAuthority());
            values.put(maxCountField, new Long((long) object.getMaxConnections()));
            String configXML = object.getConfigParams().toXML();
            values.put(configField, configXML);
            boolean notificationNeeded = false;
            boolean isCreated;

            if (set.getRowCount() > 0) {
              // If the object is supposedly new, it is bad that we found one that already exists.
              if (isNew)
                throw new ManifoldCFException(
                    "Repository connection '" + object.getName() + "' already exists");
              isCreated = false;
              IResultRow row = set.getRow(0);
              String oldXML = (String) row.getValue(configField);
              if (oldXML == null || !oldXML.equals(configXML)) notificationNeeded = true;

              // Update
              params.clear();
              query =
                  buildConjunctionClause(
                      params,
                      new ClauseDescription[] {new UnitaryClause(nameField, object.getName())});
              performUpdate(values, " WHERE " + query, params, null);
              throttleSpecManager.deleteRows(object.getName());
            } else {
              // If the object is not supposed to be new, it is bad that we did not find one.
              if (!isNew)
                throw new ManifoldCFException(
                    "Repository connection '" + object.getName() + "' no longer exists");
              isCreated = true;
              // Insert
              values.put(nameField, object.getName());
              // We only need the general key because this is new.
              performInsert(values, null);
            }

            // Write secondary table stuff
            throttleSpecManager.writeRows(object.getName(), object);

            // If notification required, do it.
            if (notificationNeeded) {
              IJobManager jobManager = JobManagerFactory.make(threadContext);
              jobManager.noteConnectionChange(object.getName());
            }

            cacheManager.invalidateKeys(ch);
            return isCreated;
          } catch (ManifoldCFException e) {
            signalRollback();
            throw e;
          } catch (Error e) {
            signalRollback();
            throw e;
          } finally {
            endTransaction();
          }
        } finally {
          cacheManager.leaveCache(ch);
        }
      } catch (ManifoldCFException e) {
        // Is this a deadlock exception?  If so, we want to try again.
        if (e.getErrorCode() != ManifoldCFException.DATABASE_TRANSACTION_ABORT) throw e;
        sleepAmt = getSleepAmt();
      } finally {
        sleepFor(sleepAmt);
      }
    }
  }