java.io.ObjectOutput Scala Examples
The following examples show how to use java.io.ObjectOutput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: FlumeInputDStream.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{Externalizable, ObjectInput, ObjectOutput} import java.net.InetSocketAddress import java.nio.ByteBuffer import java.util.concurrent.Executors import scala.collection.JavaConverters._ import scala.reflect.ClassTag import org.apache.avro.ipc.NettyServer import org.apache.avro.ipc.specific.SpecificResponder import org.apache.flume.source.avro.{AvroFlumeEvent, AvroSourceProtocol, Status} import org.jboss.netty.channel.{ChannelPipeline, ChannelPipelineFactory, Channels} import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory import org.jboss.netty.handler.codec.compression._ import org.apache.spark.internal.Logging import org.apache.spark.storage.StorageLevel import org.apache.spark.streaming.StreamingContext import org.apache.spark.streaming.dstream._ import org.apache.spark.streaming.receiver.Receiver import org.apache.spark.util.Utils private[streaming] class FlumeInputDStream[T: ClassTag]( _ssc: StreamingContext, host: String, port: Int, storageLevel: StorageLevel, enableDecompression: Boolean ) extends ReceiverInputDStream[SparkFlumeEvent](_ssc) { override def getReceiver(): Receiver[SparkFlumeEvent] = { new FlumeReceiver(host, port, storageLevel, enableDecompression) } } private[streaming] class CompressionChannelPipelineFactory extends ChannelPipelineFactory { def getPipeline(): ChannelPipeline = { val pipeline = Channels.pipeline() val encoder = new ZlibEncoder(6) pipeline.addFirst("deflater", encoder) pipeline.addFirst("inflater", new ZlibDecoder()) pipeline } } }
Example 2
Source File: EventTransformer.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectInput, ObjectOutput} import scala.collection.JavaConverters._ import org.apache.spark.internal.Logging import org.apache.spark.util.Utils private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers.asScala) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 3
Source File: BlockManagerId.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.storage import java.io.{Externalizable, IOException, ObjectInput, ObjectOutput} import java.util.concurrent.ConcurrentHashMap import org.apache.spark.SparkContext import org.apache.spark.annotation.DeveloperApi import org.apache.spark.util.Utils def apply( execId: String, host: String, port: Int, topologyInfo: Option[String] = None): BlockManagerId = getCachedBlockManagerId(new BlockManagerId(execId, host, port, topologyInfo)) def apply(in: ObjectInput): BlockManagerId = { val obj = new BlockManagerId() obj.readExternal(in) getCachedBlockManagerId(obj) } val blockManagerIdCache = new ConcurrentHashMap[BlockManagerId, BlockManagerId]() def getCachedBlockManagerId(id: BlockManagerId): BlockManagerId = { blockManagerIdCache.putIfAbsent(id, id) blockManagerIdCache.get(id) } }
Example 4
Source File: EventTransformer.scala From sparkoscope with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectInput, ObjectOutput} import scala.collection.JavaConverters._ import org.apache.spark.internal.Logging import org.apache.spark.util.Utils private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers.asScala) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 5
Source File: BlockManagerId.scala From SparkCore with Apache License 2.0 | 5 votes |
package org.apache.spark.storage import java.io.{Externalizable, IOException, ObjectInput, ObjectOutput} import java.util.concurrent.ConcurrentHashMap import org.apache.spark.SparkContext import org.apache.spark.annotation.DeveloperApi import org.apache.spark.util.Utils def apply(execId: String, host: String, port: Int) = getCachedBlockManagerId(new BlockManagerId(execId, host, port)) def apply(in: ObjectInput) = { val obj = new BlockManagerId() obj.readExternal(in) getCachedBlockManagerId(obj) } val blockManagerIdCache = new ConcurrentHashMap[BlockManagerId, BlockManagerId]() def getCachedBlockManagerId(id: BlockManagerId): BlockManagerId = { blockManagerIdCache.putIfAbsent(id, id) blockManagerIdCache.get(id) } }
Example 6
Source File: ArrayAccumulator.scala From delta with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.delta.stats import java.io.{ObjectInput, ObjectOutput} import org.apache.spark.util.AccumulatorV2 class ArrayAccumulator(val size: Int) extends AccumulatorV2[(Int, Long), Array[Long]] { protected val counts = new Array[Long](size) override def isZero: Boolean = counts.forall(_ == 0) override def copy(): AccumulatorV2[(Int, Long), Array[Long]] = { val newCopy = new ArrayAccumulator(size) (0 until size).foreach(i => newCopy.counts(i) = counts(i)) newCopy } override def reset(): Unit = (0 until size).foreach(counts(_) = 0) override def add(v: (Int, Long)): Unit = { if (v._2 == -1 || counts(v._1) == -1) { counts(v._1) = -1 } else { counts(v._1) += v._2 } } override def merge(o: AccumulatorV2[(Int, Long), Array[Long]]): Unit = { val other = o.asInstanceOf[ArrayAccumulator] assert(size == other.size) (0 until size).foreach(i => { if (counts(i) == -1 || other.counts(i) == -1) { counts(i) = -1 } else { counts(i) += other.counts(i) } }) } override def value: Array[Long] = counts }
Example 7
Source File: EventTransformer.scala From multi-tenancy-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectInput, ObjectOutput} import scala.collection.JavaConverters._ import org.apache.spark.internal.Logging import org.apache.spark.util.Utils private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers.asScala) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 8
Source File: EventTransformer.scala From iolap with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectOutput, ObjectInput} import scala.collection.JavaConversions._ import org.apache.spark.util.Utils import org.apache.spark.Logging private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 9
Source File: BlockManagerId.scala From iolap with Apache License 2.0 | 5 votes |
package org.apache.spark.storage import java.io.{Externalizable, IOException, ObjectInput, ObjectOutput} import java.util.concurrent.ConcurrentHashMap import org.apache.spark.SparkContext import org.apache.spark.annotation.DeveloperApi import org.apache.spark.util.Utils def apply(execId: String, host: String, port: Int): BlockManagerId = getCachedBlockManagerId(new BlockManagerId(execId, host, port)) def apply(in: ObjectInput): BlockManagerId = { val obj = new BlockManagerId() obj.readExternal(in) getCachedBlockManagerId(obj) } val blockManagerIdCache = new ConcurrentHashMap[BlockManagerId, BlockManagerId]() def getCachedBlockManagerId(id: BlockManagerId): BlockManagerId = { blockManagerIdCache.putIfAbsent(id, id) blockManagerIdCache.get(id) } }
Example 10
Source File: EventTransformer.scala From spark1.52 with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectOutput, ObjectInput} import scala.collection.JavaConversions._ import org.apache.spark.util.Utils import org.apache.spark.Logging private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 11
Source File: BlockManagerId.scala From spark1.52 with Apache License 2.0 | 5 votes |
package org.apache.spark.storage import java.io.{Externalizable, IOException, ObjectInput, ObjectOutput} import java.util.concurrent.ConcurrentHashMap import org.apache.spark.SparkContext import org.apache.spark.annotation.DeveloperApi import org.apache.spark.util.Utils def apply(execId: String, host: String, port: Int): BlockManagerId = getCachedBlockManagerId(new BlockManagerId(execId, host, port)) def apply(in: ObjectInput): BlockManagerId = { val obj = new BlockManagerId() obj.readExternal(in)//读取ObjectInput对象host和port_,executorId_ getCachedBlockManagerId(obj)//获取BlockManagerId } val blockManagerIdCache = new ConcurrentHashMap[BlockManagerId, BlockManagerId]() def getCachedBlockManagerId(id: BlockManagerId): BlockManagerId = { blockManagerIdCache.putIfAbsent(id, id)//put和putIfAbsent的区别就是一个是直接放入并替换,另一个是有就不替换 blockManagerIdCache.get(id)//返回BlockManagerId对象 } }
Example 12
Source File: EventTransformer.scala From Spark-2.3.1 with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectInput, ObjectOutput} import scala.collection.JavaConverters._ import org.apache.spark.internal.Logging import org.apache.spark.util.Utils private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers.asScala) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 13
Source File: EventTransformer.scala From BigDatalog with Apache License 2.0 | 5 votes |
package org.apache.spark.streaming.flume import java.io.{ObjectOutput, ObjectInput} import scala.collection.JavaConverters._ import org.apache.spark.util.Utils import org.apache.spark.Logging private[streaming] object EventTransformer extends Logging { def readExternal(in: ObjectInput): (java.util.HashMap[CharSequence, CharSequence], Array[Byte]) = { val bodyLength = in.readInt() val bodyBuff = new Array[Byte](bodyLength) in.readFully(bodyBuff) val numHeaders = in.readInt() val headers = new java.util.HashMap[CharSequence, CharSequence] for (i <- 0 until numHeaders) { val keyLength = in.readInt() val keyBuff = new Array[Byte](keyLength) in.readFully(keyBuff) val key: String = Utils.deserialize(keyBuff) val valLength = in.readInt() val valBuff = new Array[Byte](valLength) in.readFully(valBuff) val value: String = Utils.deserialize(valBuff) headers.put(key, value) } (headers, bodyBuff) } def writeExternal(out: ObjectOutput, headers: java.util.Map[CharSequence, CharSequence], body: Array[Byte]) { out.writeInt(body.length) out.write(body) val numHeaders = headers.size() out.writeInt(numHeaders) for ((k, v) <- headers.asScala) { val keyBuff = Utils.serialize(k.toString) out.writeInt(keyBuff.length) out.write(keyBuff) val valBuff = Utils.serialize(v.toString) out.writeInt(valBuff.length) out.write(valBuff) } } }
Example 14
Source File: BlockManagerId.scala From BigDatalog with Apache License 2.0 | 5 votes |
package org.apache.spark.storage import java.io.{Externalizable, IOException, ObjectInput, ObjectOutput} import java.util.concurrent.ConcurrentHashMap import org.apache.spark.SparkContext import org.apache.spark.annotation.DeveloperApi import org.apache.spark.util.Utils def apply(execId: String, host: String, port: Int): BlockManagerId = getCachedBlockManagerId(new BlockManagerId(execId, host, port)) def apply(in: ObjectInput): BlockManagerId = { val obj = new BlockManagerId() obj.readExternal(in) getCachedBlockManagerId(obj) } val blockManagerIdCache = new ConcurrentHashMap[BlockManagerId, BlockManagerId]() def getCachedBlockManagerId(id: BlockManagerId): BlockManagerId = { blockManagerIdCache.putIfAbsent(id, id) blockManagerIdCache.get(id) } }
Example 15
Source File: LogEntry.scala From infinispan-spark with Apache License 2.0 | 5 votes |
package org.infinispan.spark.domain import java.io.{ObjectInput, ObjectOutput} import java.time.LocalDate import java.time.temporal.ChronoUnit import org.infinispan.commons.io.UnsignedNumeric import org.infinispan.commons.marshall._ @SerializeWith(classOf[LogEntrySerializer]) class LogEntry(val date: LocalDate, var opCode: Int, val userAgent: String, val domain: String) class LogEntrySerializer extends Externalizer[LogEntry] { override def writeObject(output: ObjectOutput, obj: LogEntry): Unit = { output.writeObject(obj.date) UnsignedNumeric.writeUnsignedInt(output, obj.opCode) output.writeUTF(obj.userAgent) output.writeUTF(obj.domain) } override def readObject(input: ObjectInput): LogEntry = { val date = input.readObject().asInstanceOf[LocalDate] val opCode = UnsignedNumeric.readUnsignedInt(input) val userAgent = input.readUTF() val domain = input.readUTF() new LogEntry(date, opCode, userAgent, domain) } } object EntryGenerator { val browser = Set("Firefox", "Chrome", "MSIE") val domainNames = Set("no-ip.org", "dnf.it", "google.com", "localhost") def generate(numEntries: Int, errorCondition: LogEntry => Boolean, startDate: LocalDate, endDate: LocalDate) = { val userAgentsIterator = circularIterator(browser) val domainNamesIterator = circularIterator(domainNames) val diffDays = ChronoUnit.DAYS.between(startDate, endDate) val daysPerEntry = diffDays.toFloat / numEntries.toFloat (1 to numEntries).map { i => val browser = userAgentsIterator.next() val domain = domainNamesIterator.next() val dateTime = startDate.plusDays(Math.floor(daysPerEntry * i).toInt) val entry = new LogEntry(dateTime, 0, browser, domain) val op = if (errorCondition(entry)) 500 else 200 entry.opCode = op entry }.toList } private def circularIterator[T](s: Set[T]) = Iterator.continually(s).flatten }