精华内容
下载资源
问答
  • Broadcast

    2019-10-30 11:37:39
    Broadcast 广播 Broadcast 可以将数据广播到每个节点上,这样节点需要使用该数据是无需发送请求,大大提升了效率。 Broadcast 提供了接口,具体的方法在子类中实现,如子类TorrentBroadcast。 源码清单和我的理解...

    Broadcast 广播

    Broadcast 可以将数据广播到每个节点上,这样节点需要使用该数据是无需发送请求,大大提升了效率。
    Broadcast 提供了接口,具体的方法在子类中实现,如子类TorrentBroadcast。

    源码清单和我的理解注释

    ListenerBus源码中第一行,创建了一个线程安全的ArrayList——CopyOnWriteArrayList,之后添加、者删除事件等操作都在这个线程安全的ArrayList中执行

    /**
       * 标记广播变量是否有效的标志
       */
      @volatile private var _isValid = true
    
    /** 先判断广播变量是否有效再获取值 */
      def value: T = {
        assertValid()
        getValue()
      }
    

    删除执行器excutor中的广播副本

    /**
       * Asynchronously delete cached copies of this broadcast on the executors.
       * If the broadcast is used after this is called, it will need to be re-sent to each executor.
       */
      def unpersist() {
        unpersist(blocking = false)
      }
    
      /**
       * Delete cached copies of this broadcast on the executors. If the broadcast is used after
       * this is called, it will need to be re-sent to each executor.
       * @param blocking Whether to block until unpersisting has completed
       */
      def unpersist(blocking: Boolean) {
        assertValid()
        doUnpersist(blocking)
      }
    

    摧毁广播变量

     /**
       * Destroy all data and metadata related to this broadcast variable. Use this with caution;
       * once a broadcast variable has been destroyed, it cannot be used again.
       * This method blocks until destroy has completed
       * 摧毁与此广播变量相关的所有数据和元数据,一旦摧毁便无法再使用它
       * 这个函数将被阻塞,直到摧毁工作完成
       */
      def destroy() {
        destroy(blocking = true)
      }
    
      /**
       * Destroy all data and metadata related to this broadcast variable. Use this with caution;
       * once a broadcast variable has been destroyed, it cannot be used again.
       * @param blocking Whether to block until destroy has completed
       * 摧毁与此广播变量相关的所有数据和元数据,一旦摧毁便无法再使用它
       * 参数blocking可以选择是否在摧毁完成前阻止摧毁工作
       */
      private[spark] def destroy(blocking: Boolean) {
        assertValid()
        _isValid = false
        _destroySite = Utils.getCallSite().shortForm
        logInfo("Destroying %s (from %s)".format(toString, _destroySite))
        doDestroy(blocking)
      }
    
    展开全文
  • BroadCast

    2018-09-30 18:13:08
    使用打开关闭数据网络,触发BroadCast 1、新建BroadCastTest工程; 2、新建MyBroadCast  在OnReceive()增加一句显示代码 Toast.maketext().show(); 3、在MainActivity中定义两个变量;  private ...

    使用打开关闭数据网络,触发BroadCast

    1、新建BroadCastTest工程;

    2、新建MyBroadCast

       在OnReceive()增加一句显示代码 Toast.maketext().show();

    3、在MainActivity中定义两个变量;

       private IntentFilter intentFilter;启动intent,带action;

       private  MyBroadCast myBroadCast;

      intentFilter=new IntentFilter();

      intentFilter.action("android.net.conn.CONNECTION_CHANGE");

      myBroadCast=new MyBroadCast();

      regesterreceiver(myBroadCast,intentFilter);//注册自定义的BroadCast,带一个Action;

     

    4、OnDestroy()

        unregesterreceiver(myBroadCast);

     

    5、在AndroidMainifest.xml中填写:

         <use-permission android :name="android.permission.ACCESS_NETWORK_STATE"/>

    展开全文
  • broadcast

    2013-03-26 15:34:23
    在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制。而BroadcastReceiver是对发送出来的 Broadcast进行过滤接受并响应的一类组件。 下面将详细的阐述如何发送Broadcast和使用BroadcastReceiver...

    在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制。而BroadcastReceiver是对发送出来的 Broadcast进行过滤接受并响应的一类组件。

    下面将详细的阐述如何发送Broadcast和使用BroadcastReceiver过滤接收的过程:

      首先在需要发送信息的地方,把要发送的信息和用于过滤的信息(如Action、Category)装入一个Intent对象,然后通过调用 sendOrderBroadcast()或sendStickyBroadcast()方法,把 Intent对象以广播方式发送出去。

      当Intent发送以后,所有已经注册的BroadcastReceiver会检查注册时的IntentFilter是否与发送的Intent相匹配,若匹配则就会调用BroadcastReceiver的onReceive()方法。所以当我们定义一个BroadcastReceiver的时候,都需要实现onReceive()方法。

      注册BroadcastReceiver有两种方式:

      静态注册:在AndroidManifest.xml中用标签生命注册,并在标签内用标签设置过滤器。

      <receiver android:name="myRecevice">    //继承BroadcastReceiver,重写onReceiver方法

        <intent-filter>    

          <action android:name="com.dragon.net"></action> //使用过滤器,接收指定action广播

          </intent-filter>

      </receiver> 

      动态注册:

      IntentFilter intentFilter = new IntentFilter();

      intentFilter.addAction(String);   //为BroadcastReceiver指定action,使之用于接收同action的广播

          registerReceiver(BroadcastReceiver,intentFilter);

      一般:在onStart中注册,onStop中取消unregisterReceiver

      指定广播目标Action:Intent intent = new Intent(actionString);

      并且可通过Intent携带消息 :intent.putExtra("msg", "hi,我通过广播发送消息了");

      发送广播消息:Context.sendBroadcast(intent )

     

    其中在动态注册中可将BroadcastReceiver的继承类进行封装,添加构造函数和BroadcastReceiver注册

     

    代码
    复制代码
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;

    public class BroadcastReceiverHelper extends BroadcastReceiver {

    NotificationManager mn
    =null;
    Notification notification
    =null;
    Context ct
    =null;
    BroadcastReceiverHelper receiver;

    public BroadcastReceiverHelper(Context c){
    ct
    =c;
    receiver
    =this;
    }

    //注册
    public void registerAction(String action){
    IntentFilter filter
    =new IntentFilter();
    filter.addAction(action);
    ct.registerReceiver(receiver, filter);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    String msg=intent.getStringExtra("msg");
    int id=intent.getIntExtra("who", 0);
    if(intent.getAction().equals("com.cbin.sendMsg")){
    mn
    =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    notification
    =new Notification(R.drawable.icon, id+"发送广播", System.currentTimeMillis());
    Intent it
    = new Intent(context,Main.class);
    PendingIntent contentIntent
    =PendingIntent.getActivity(context,
    0, it, 0);
    notification.setLatestEventInfo(context,
    "msg", msg, contentIntent);
    mn.notify(
    0, notification);
    }
    }
    }
    复制代码

     

    然后再Activity中声明BroadcastReceiver的扩展对象,在onStart中注册,onStop中卸载

     

    代码
    复制代码

    BroadcastReceiverHelper rhelper;
    @Override
    public void onStart(){
    //注册广播接收器
    rhelper=new BroadcastReceiverHelper(this);
    rhelper.registerAction(
    "com.cbin.sendMsg");
    super.onStart();
    }

    @Override
    public void onStop(){
    //取消广播接收器
    unregisterReceiver(rhelper);
    super.onStop();
    }
    复制代码

     总结:

    1、broadcastreceiver 处理时间不得超过10秒,否则出现ANR错误。

    2、broadcastreceiver中onreceive执行完后,该receiver对象就被销毁了,下次使用会重新创建新的receiver对象。

    3、静态注册的receiver在其程序启动后就常驻系统,即使该程序退出ondestroy后(或重启手机后),receiver仍能接收广播。除非卸载该程序。

        动态注册的receiver在程序退出后就不再接收广播。


    展开全文
  • BroadcastManager

    2019-04-20 09:07:38
    Broadcast是分布式的数据共享,由BroadcastManager负责管理其创建或销毁。Broadcast一般用于处理共享的配置文件、通用Dataset、常用数据结构 1.1、创建 通过SparkContext.broadcast广播一个Broadcast, 实际调用的是...

    Broadcast是分布式的数据共享,由BroadcastManager负责管理其创建或销毁。Broadcast一般用于处理共享的配置文件、通用Dataset、常用数据结构

    1.1、创建

    通过SparkContext.broadcast广播一个Broadcast, 实际调用的是SparkEnv的BroadManager来创建

      /**
       * Broadcast a read-only variable to the cluster, returning a
       * [[org.apache.spark.broadcast.Broadcast]] object for reading it in distributed functions.
       * The variable will be sent to each cluster only once.
       */
      def broadcast[T: ClassTag](value: T): Broadcast[T] = {
        assertNotStopped()
        require(!classOf[RDD[_]].isAssignableFrom(classTag[T].runtimeClass),
          "Can not directly broadcast RDDs; instead, call collect() and broadcast the result.")
        //使用SparkEnv.broadcastManager创建Broadcast
        val bc = env.broadcastManager.newBroadcast[T](value, isLocal)
        val callSite = getCallSite
        logInfo("Created broadcast " + bc.id + " from " + callSite.shortForm)
        cleaner.foreach(_.registerBroadcastForCleanup(bc))
        bc
      }
    

    1.1.1、在SparkEnv中创建BroadcastManager,

    // 此处只是声明, 只有调用initialize, 才会生效
    val broadcastManager = new BroadcastManager(isDriver, conf, securityManager)
    

    1.1.2、initialize

    // Called by SparkContext or Executor before using Broadcast
      private def initialize() {
        synchronized {
          if (!initialized) {
            broadcastFactory = new TorrentBroadcastFactory
            broadcastFactory.initialize(isDriver, conf, securityManager)
            initialized = true
          }
        }
      }
    

    1.1.3、 BoradcastManager操作BradCast实际是代理BroadcastFactory, 此处使用工厂模式

      def stop() {
        broadcastFactory.stop()
      }
    
      private val nextBroadcastId = new AtomicLong(0)
    
      def newBroadcast[T: ClassTag](value_ : T, isLocal: Boolean): Broadcast[T] = {
        broadcastFactory.newBroadcast[T](value_, isLocal, nextBroadcastId.getAndIncrement())
      }
    
      def unbroadcast(id: Long, removeFromDriver: Boolean, blocking: Boolean) {
        broadcastFactory.unbroadcast(id, removeFromDriver, blocking)
      }
    
    
    展开全文
  • Align broadcast

    2020-12-08 18:03:44
    <div><ul><li>Removed partial_align()</li><li>Added exclude and indexes optional parameters to align() public API</li><li>Added exclude optional parameter to broadcast() public API</li><li>Added ...
  • Broadcast Locally

    2020-12-26 04:36:44
    <p>But on my app I do not receive any broadcast. When I try my app with a System Broadcast that works. <p>Can you help me to find any reason for that? How can I check that xDrip send the Broadcast ...
  • Versioned broadcast

    2021-01-07 05:53:09
    <div><p><code>BroadcastMinVersion</code> and <code>BroadcastMaxVersion</code> broadcast only to peers that are of at least or at most the specified version, respectively. This is necessary for the ...
  • E0529 11:37:28.128362 31042 elementwise_op_function.h:1068] Error, broadcast should not into w broadcast E0529 11:37:28.128648 31040 elementwise_op_function.h:1068] Error, broadcast should not into w ...
  • 浅析Broadcast

    2020-04-15 17:40:09
    浅析 Broadcast 主要有三种对象 BroadcastManager、BroadcastFactory 和 Broadcast BroadcastManager 负责Broadcast的全局管理 BroadcastFactory 负责创建或取消Broadcast Broadcast 为实际的一次广播操作 ...
  • broadcast intent

    2020-03-30 22:53:54
    broadcast intent概述接受系统broadcast: 重启后唤醒过滤前台消息通知消息使用私有权限限制broadcast 概述 Intent可以使用sendBroadcast(), 在应用组件之间广播事件; 使用BroadReceiver类监听和响应Broadcast ...
  • broadcastbroadcast receiver我们需要注意,广播与广播接收者的区别广播接收者的注册一般面试官会问,广播的注册方式有几种,最好能解释一下,广播注册指的是广播接收者的注册。静态注册也就是在AndroidManifests....
  • Spark Broadcast

    2018-09-05 21:44:28
    顾名思义,broadcast 就是将数据从一个节点发送到其他各个节点上去。这样的场景很多,比如 driver 上有一张表,其他节点上运行的 task 需要 lookup 这张表,那么 driver 可以先把这张表 copy 到这些节点,这样 task ...
  • 第42课: Spark Broadcast内幕解密:Broadcast运行机制彻底解密、Broadcast源码解析、Broadcast最佳实践Broadcast在机器学习、图计算、构建日常的各种算法中到处可见。 Broadcast就是将数据从一个节点发送到其它的...
  • Broadcast 运行原理图 Broadcast 源码解析   Broadcast 运行原理图 Broadcast 就是将数据从一个节点发送到其他的节点上; 例如 Driver 上有一张表,而 Executor 中的每个并行执行的Task (100万个Task) 都要...
  • Broadcast variable support

    2020-12-31 14:10:54
    <p><strong>Broadcast variables</strong> allow the programmer to keep a read-only variable cached on each machine rather than shipping a copy of it with tasks. They can be used, for example, to give ...
  • BroadCast Channel

    2020-04-11 17:08:56
    BroadCast Channel 可以帮我们创建一个用于广播的通信频道。当监听同一频道的某个页面通过它发送消息时就会被其他所有页面收到。 // 使用构造函数创建一个实例,可以接受一个DOMString作为频道的name标识。在其他...
  • Feature lwip broadcast

    2021-01-09 13:00:37
    <p>Implement to SO_BROADCAST socket option and provide a UDPSocket::set_broadcast(bool) method. <pre><code>cpp sock.set_broadcast(true); // Enable reception of broadcast packets </code></pre> <p>Fix ...
  • Android Broadcast

    2015-12-17 09:08:33
    Android Broadcast
  • 本课主题 Broadcast运行原理图 ... 例如 Driver 上有一张表,而 Executor 中的每个并行执行的Task (100万个Task) 都要查询这张表的话,那我们通过 Broadcast 的方式就只需要往每个Executor 把这张表发送一次...
  • scala broadcast

    千次阅读 2017-05-03 16:42:31
    scala> val broadcastVar = sc.broadcast(Array(1, 2, 3)) broadcastVar: org.apache.spark.broadcast.Broadcast[Array[Int]] = Broadcast(0) scala> broadcastVar.value res0: Array[Int] = Array(1, 2, 3)
  • example-broadcast

    2021-01-08 19:10:42
    <p>I am creating a communication between two cc13xx devices with the sample-broadcast. I wanted to change the code, turning on a led from one device to another but I can not transmit. He manages to ...
  • Android四大组件之Broadcast Receiver 作者:白璐 日期:2020/2/23 文章目录Android四大组件之Broadcast Receiver概述广播接收器(Broadcast Receiver)Broadcast Receiver简介Broadcast Receiver的注册一. 静态注册...
  • 当Android系统发生某种状况,必须通知所有程序进行处理时,例如电量不足等,可利用Broadcast Intent对象的功能来进行信息广播。 运行机制包括两部:送出Intent对象的程序;监听广播信息的程序(Broadcast Receiver)...
  • Broadcast广播

    2017-05-26 09:22:42
    1.1 Broadcast Receiver广播接收器 它和事件处理机制类似,只不过事件处理机制是程序组件级别,而广播事件机制是系统级别的。 BroadcastReceiver对象仅在调用onReceiver()方法时有效,当该方法执行完毕后,系统会...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 26,869
精华内容 10,747
关键字:

broadcast