Пример #1
0
  /**
   * Get the behaviour for the activity specified
   *
   * @param toActivity the activity to get the activity for
   * @param <K> the type of the activity
   * @return the behaviour or null if no behaviour was found
   */
  public <K extends IActivity> Behaviour<K> getBehaviourFor(K toActivity) {
    // First check for a live behaviour
    if (m_oActivityMap != null && m_oActivityMap.containsKey(toActivity)) {
      return (Behaviour<K>) m_oActivityMap.get(toActivity);
    }

    if (m_oBehaviourMap != null && m_oBehaviourMap.containsKey(toActivity.getClass())) {
      List<Class<? extends Behaviour<? extends IActivity>>> loBehaviours =
          m_oBehaviourMap.get(toActivity.getClass());
      for (Class<? extends Behaviour<? extends IActivity>> loBehaviourClass : loBehaviours) {
        try {
          Behaviour<K> loBehaviour = (Behaviour<K>) loBehaviourClass.newInstance();
          if (loBehaviour.isValid(toActivity)) {
            if (m_oActivityMap == null) {
              m_oActivityMap = new HashMap<IActivity, Behaviour<? extends IActivity>>();
            }
            m_oActivityMap.put(toActivity, loBehaviour);
            return loBehaviour;
          }
        } catch (InstantiationException ex) {
          Application.log(ex);
        } catch (IllegalAccessException ex) {
          Application.log(ex);
        }
      }
    }
    return null;
  }
Пример #2
0
 private void checkKey(K keyObject) {
   if (keyObject == null) {
     throw new NullPointerException();
   }
   if (!keyType.isAssignableFrom(keyObject.getClass())) {
     throw new ClassCastException(
         "Invalid key type, expected : "
             + keyType.getName()
             + " but was : "
             + keyObject.getClass().getName());
   }
 }
Пример #3
0
 /**
  * Return the persistent instance of the given entity class with the given identifier, or null if
  * there is no such persistent instance. (If the instance is already associated with the session,
  * return that instance. This method never returns an uninitialized instance.)
  *
  * @param id an identifier
  * @return a persistent instance or null
  * @throws HibernateException Indicates a problem either translating the criteria to SQL,
  *     executing the SQL or processing the SQL results.
  */
 @SuppressWarnings("unchecked")
 public T getById(K id) {
   T result = null;
   Session session = null;
   // get the current session
   session = sessionFactory.getCurrentSession();
   try {
     // perform database access (query, insert, update, etc) here
     try {
       if (id.getClass().getName().startsWith(this.getClass().getPackage().getName())) {
         result = clazz.newInstance();
         result.setId(id);
         result = (T) session.get(clazz, result);
       } else {
         result = (T) session.get(clazz, id);
       }
     } catch (InstantiationException e) {
       result = (T) session.get(clazz, id);
     } catch (IllegalAccessException e) {
       result = (T) session.get(clazz, id);
     }
   } catch (HibernateException e) {
     exceptionHandling(e, session);
   }
   // return result, if needed
   return result;
 }
Пример #4
0
 /**
  * JavaPropertyManager stored data as strings at the moment, so need to convert to the correct
  * type here
  *
  * @param taPath the path of the property to get
  * @param toDefault the default value of the property
  * @param <K> the type of the value
  * @return the value or null if there was no value of this type
  */
 @SuppressWarnings("unchecked")
 @Override
 protected <K> K onGetProperty(String[] taPath, K toDefault) {
   K loReturn = onGetProperty(taPath);
   if (loReturn == null) {
     setProperty(taPath, toDefault);
     loReturn = toDefault;
   } else {
     loReturn = (K) Java.stringToPrimitive((String) loReturn, toDefault.getClass());
   }
   return loReturn;
 }
Пример #5
0
 public void initialize(InputSplit split, TaskAttemptContext context)
     throws IOException, InterruptedException {
   rr.initialize(split, context);
   conf = context.getConfiguration();
   nextKeyValue();
   if (!empty) {
     keyclass = key.getClass().asSubclass(WritableComparable.class);
     valueclass = value.getClass();
     if (cmp == null) {
       cmp = WritableComparator.get(keyclass, conf);
     }
   }
 }
Пример #6
0
  private String buildSolrId(K key) {
    JsonObject jsonKey = new JsonObject();
    if (key instanceof String) {
      jsonKey.putString("C", "S");
      jsonKey.putString("V", (String) key);
    } else {
      jsonKey.putString("C", key.getClass().getName());
      jsonKey.putString("V", JsonObject.toJson(key));
    }
    String id = _mapName + ":" + jsonKey.encode();

    return id;
  }
Пример #7
0
 /** For a given RecordReader rr, occupy position id in collector. */
 WrappedRecordReader(int id, RecordReader<K, U> rr, Class<? extends WritableComparator> cmpcl)
     throws IOException {
   this.id = id;
   this.rr = rr;
   khead = rr.createKey();
   vhead = rr.createValue();
   try {
     cmp = (null == cmpcl) ? WritableComparator.get(khead.getClass()) : cmpcl.newInstance();
   } catch (InstantiationException e) {
     throw (IOException) new IOException().initCause(e);
   } catch (IllegalAccessException e) {
     throw (IOException) new IOException().initCause(e);
   }
   vjoin = new StreamBackedIterator<U>();
   next();
 }
Пример #8
0
 Node<K, V> find(K key, boolean create) {
   Comparator<? super K> comparator = this.comparator;
   Node<K, V> nearest = this.root;
   int comparison = 0;
   if (nearest != null) {
     Comparable<Object> comparableKey = comparator == NATURAL_ORDER ? (Comparable) key : null;
     while (true) {
       comparison =
           comparableKey != null
               ? comparableKey.compareTo(nearest.key)
               : comparator.compare(key, nearest.key);
       if (comparison == 0) {
         return nearest;
       }
       Node<K, V> child = comparison < 0 ? nearest.left : nearest.right;
       if (child == null) {
         break;
       }
       nearest = child;
     }
   }
   if (!create) {
     return null;
   }
   Node<K, V> created;
   Node<K, V> header = this.header;
   if (nearest != null) {
     created = new Node(nearest, key, header, header.prev);
     if (comparison < 0) {
       nearest.left = created;
     } else {
       nearest.right = created;
     }
     rebalance(nearest, true);
   } else if (comparator != NATURAL_ORDER || (key instanceof Comparable)) {
     created = new Node(nearest, key, header, header.prev);
     this.root = created;
   } else {
     throw new ClassCastException(key.getClass().getName() + " is not Comparable");
   }
   this.size++;
   this.modCount++;
   return created;
 }
Пример #9
0
    @SuppressWarnings("unchecked")
    public synchronized void collect(K key, V value) throws IOException {
      reporter.progress();
      if (key.getClass() != keyClass) {
        throw new IOException(
            "Type mismatch in key from map: expected "
                + keyClass.getName()
                + ", recieved "
                + key.getClass().getName());
      }
      if (value.getClass() != valClass) {
        throw new IOException(
            "Type mismatch in value from map: expected "
                + valClass.getName()
                + ", recieved "
                + value.getClass().getName());
      }
      if (sortSpillException != null) {
        throw (IOException) new IOException("Spill failed").initCause(sortSpillException);
      }
      try {
        // serialize key bytes into buffer
        int keystart = bufindex;
        keySerializer.serialize(key);
        if (bufindex < keystart) {
          // wrapped the key; reset required
          bb.reset();
          keystart = 0;
        }
        // serialize value bytes into buffer
        int valstart = bufindex;
        valSerializer.serialize(value);
        int valend = bb.markRecord();
        mapOutputByteCounter.increment(
            valend >= keystart ? valend - keystart : (bufvoid - keystart) + valend);

        if (keystart == bufindex) {
          // if emitted records make no writes, it's possible to wrap
          // accounting space without notice
          bb.write(new byte[0], 0, 0);
        }

        int partition = partitioner.getPartition(key, value, partitions);
        if (partition < 0 || partition >= partitions) {
          throw new IOException("Illegal partition for " + key + " (" + partition + ")");
        }
        mapOutputRecordCounter.increment(1);

        // update accounting info
        int ind = kvindex * ACCTSIZE;
        kvoffsets[kvindex] = ind;
        kvindices[ind + PARTITION] = partition;
        kvindices[ind + KEYSTART] = keystart;
        kvindices[ind + VALSTART] = valstart;
        kvindex = (kvindex + 1) % kvoffsets.length;
      } catch (MapBufferTooSmallException e) {
        LOG.info("Record too large for in-memory buffer: " + e.getMessage());
        spillSingleRecord(key, value);
        mapOutputRecordCounter.increment(1);
        return;
      }
    }
Пример #10
0
  @Override
  public MutableFudgeMsg buildMessage(FudgeSerializer serializer, final T auto) {
    MutableFudgeMsg outerMsg = serializer.newMessage();
    outerMsg.add(
        null,
        FudgeSerializer.TYPES_HEADER_ORDINAL,
        FudgeWireType.STRING,
        AutoFudgable.class.getName());
    final K inner = auto.object();
    assertValid(inner.getClass());
    try {
      MutableFudgeMsg msg = outerMsg.addSubMessage("inner", null);
      // save the internal class name
      msg.add(
          null,
          FudgeSerializer.TYPES_HEADER_ORDINAL,
          FudgeWireType.STRING,
          inner.getClass().getName());

      // save the ctor parameters
      List<Object> parameters =
          AccessController.doPrivileged(
              new PrivilegedAction<List<Object>>() {
                @Override
                public List<Object> run() {
                  try {
                    final Constructor<?>[] ctors = inner.getClass().getDeclaredConstructors();
                    // We require that inner classes got only one ctor (anonymous inner classes will
                    // do)
                    // in order to avoid disambiguity
                    if (ctors.length == 1) {
                      final Constructor<?> ctor = ctors[0];
                      // types of parameters of ctor
                      final Class<?>[] parameterTypes = ctor.getParameterTypes();
                      // all declared parameters of the inner class
                      final Field[] fs = inner.getClass().getDeclaredFields();
                      // extracting copiler synthetized fields of inner class
                      // first are the not sinthetized fields (regular ones) we need to skip
                      // then there are compiler synthetized fields with corresponds to ctor
                      // parameters
                      // the last field is the reference to enclosing object so we need to skipp it
                      // as well
                      final Field[] paramFields =
                          Arrays.copyOfRange(fs, fs.length - parameterTypes.length, fs.length - 1);
                      final List<Object> parameters = newArrayList();
                      for (Field paramField : paramFields) {
                        paramField.setAccessible(true);
                        parameters.add(paramField.get(inner));
                      }
                      return parameters;
                    }
                  } catch (IllegalAccessException e) {
                    // Ignore
                  }
                  return null;
                }
              });

      for (Object parameter : parameters) {
        // save the ctor parameter
        serializer.addToMessageWithClassHeaders(msg, null, 1, parameter);
      }
      return outerMsg;

    } catch (RuntimeException ex) {
      throw new FudgeRuntimeException("Unable to serialize: " + inner.getClass().getName(), ex);
    }
  }
 public V resolve(K key) {
   return resolve((Class<? extends K>) key.getClass());
 }
Пример #12
0
    @Override
    public void map(K key, V value, OutputCollector<K, V> output, Reporter reporter)
        throws IOException {
      // TODO Auto-generated method stub
      // doing the filter

      // <key,value>
      // <[AttemptID/PhaseStack/PhaseAlias],
      // [ThreadName,ThreadId,starttime,endtime,funlist,funcountlist,statelist,statecountlist,funStateMatric]>
      HiTuneRecord valproxy = new HiTuneRecord(value);
      String hostname = valproxy.getHost();
      String status = valproxy.getValue("ThreadState");
      String stack = valproxy.getValue("CallStack");
      String attemptID = valproxy.getValue("TaskID");
      log.debug(
          "hostname:"
              + hostname
              + " ThreadState:"
              + status
              + " stack:"
              + stack
              + " attemptID:"
              + attemptID);
      if (isMatched(this.nodelist, hostname)) {
        for (String s : phasealias.keySet()) {
          log.debug("phasealias:" + s);
          if (s == null || s.length() == 0) s = "";
          Pattern p = Pattern.compile(s);
          if (stack != null && stack.length() != 0) stack = stack.replace(" ", "");
          else stack = "";
          Matcher matcher = p.matcher(stack);
          if (matcher.find()) {
            try {
              log.debug("find pattern");
              K newkey = (K) key.getClass().getConstructor().newInstance();
              V newval = (V) value.getClass().getConstructor().newInstance();

              HiTuneKey newkeyproxy = new HiTuneKey(newkey);
              HiTuneRecord newvalproxy = new HiTuneRecord(newval);

              newkeyproxy.setKey(attemptID + "/" + s + "/" + phasealias.get(s));
              newkeyproxy.setDataType(new HiTuneKey(key).getDataType());
              newvalproxy.copyCommonFields(value);

              newvalproxy.add("thread_id", valproxy.getValue("ThreadID"));
              newvalproxy.add("thread_name", valproxy.getValue("ThreadName"));
              newvalproxy.add("attempt_id", attemptID);
              newvalproxy.add("phase_stack", s);
              newvalproxy.add("phase_name", phasealias.get(s));
              newvalproxy.add("start", "" + newvalproxy.getTime());
              newvalproxy.add("count", "1");
              log.debug("status:" + conf.get("status"));
              newvalproxy.add("statusList", conf.get("status"));
              newvalproxy.add("statusCount", count(status, this.statuslist));

              log.debug("funList:" + this.phases.get(s));
              newvalproxy.add("funList", List2String(this.phases.get(s), SEPERATOR_COMMA));
              newvalproxy.add("funCount", count(stack, this.phases.get(s)));
              newvalproxy.add(
                  AnalysisProcessorConfiguration.jobid,
                  conf.get(AnalysisProcessorConfiguration.jobid));

              log.debug("Key:" + newkeyproxy.toString() + " Record" + newkeyproxy.toString());
              output.collect((K) newkeyproxy.getObject(), (V) newvalproxy.getObject());
            } catch (IllegalArgumentException e) {
              // TODO Auto-generated catch block
              log.warn(e);
              e.printStackTrace();
            } catch (SecurityException e) {
              // TODO Auto-generated catch block
              log.warn(e);
              e.printStackTrace();
            } catch (InstantiationException e) {
              // TODO Auto-generated catch block
              log.warn(e);
              e.printStackTrace();
            } catch (IllegalAccessException e) {
              // TODO Auto-generated catch block
              log.warn(e);
              e.printStackTrace();
            } catch (InvocationTargetException e) {
              // TODO Auto-generated catch block
              log.warn(e);
              e.printStackTrace();
            } catch (NoSuchMethodException e) {
              // TODO Auto-generated catch block
              log.warn(e);
              e.printStackTrace();
            }
          }
        }
      }
    }