Пример #1
0
 public void saveCache(
     JMXInstrumentedCache<K, V> cache, File savedCachePath, Function<K, byte[]> converter)
     throws IOException {
   long start = System.currentTimeMillis();
   String msgSuffix = " " + savedCachePath.getName() + " for " + cfname + " of " + ksname;
   logger.debug("saving" + msgSuffix);
   int count = 0;
   File tmpFile =
       File.createTempFile(savedCachePath.getName(), null, savedCachePath.getParentFile());
   FileOutputStream fout = new FileOutputStream(tmpFile);
   ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fout));
   FileDescriptor fd = fout.getFD();
   for (K key : cache.getKeySet()) {
     byte[] bytes = converter.apply(key);
     out.writeInt(bytes.length);
     out.write(bytes);
     ++count;
   }
   out.flush();
   fd.sync();
   out.close();
   if (!tmpFile.renameTo(savedCachePath))
     throw new IOException("Unable to rename cache to " + savedCachePath);
   if (logger.isDebugEnabled())
     logger.debug(
         "saved "
             + count
             + " keys in "
             + (System.currentTimeMillis() - start)
             + " ms from"
             + msgSuffix);
 }
Пример #2
0
 // Sends the message stored in prefix+message to the server
 public synchronized void sendMessage(byte prefix, byte[] message) throws IOException {
   if (handlers[prefix].shouldSendToSelf()) sendToSelf(prefix, message);
   oos.write(prefix);
   oos.write(message);
   oos.flush();
 }