首页 文章 精选 留言 我的

精选列表

搜索[监督学习],共10000篇文章
优秀的个人博客,低调大师

Android 利用【Hierarchy Viewer 】 工具学习别人的UI设计

在Android 工具栏里面,地址:D:\Program Files\android-sdk-windows\tools 目录下打开此工具 此工具名为:层级观察器 本篇文章将教大家如何利用层级观察器查看和优化自己的UI层次关系或者看别人应用程序UI的布局结构,双击该处理文件,显示如下 图: 左边为设备列表名称,如果你开启多个设备将会一一列出你当前运行的设备,包括真机。 右边是当前设备列表运行的Acitivity ,即你当前运行的Activity 对应的UI布局,本篇将使用Android 自身的音乐播放器,来操作得到UI布局结构,这里的我们要点击 com.android.music/com.android.music.MediaPlaybackActivity 项,选中它,到上面点击Load View Hierarchy 项,右下角将会出现加载进度条,然后将加载的View 结构显示出来,如下图: 左边为UI 的关系图 右边为每个View 的属性(必须选中任意View 对象)和结构草图底下是关系图的缩略图 底下进度条可以控制关系的显示大小 左下角两个按钮为缩略显示和列表显示方式,先把列表显示方式为如下图: 左边为布局中使用的ViewGroup和View 的关系结构图,点中任意的一个View 对象右边都会帮我们获得焦点 右边为显示当前Activity 在真机运行的效果图,我记得有个朋友在QQ群问过,有没有什么工具可以得到坐标的,其实这个工具就可以坐到,看最右下角,分别为RGB 和XY 轴,我们点击屏幕的任意为置,它都会帮我们算出来当前显示的值,怎么样是不是很实用的一个工具。快去试试吧 Tip:最上边的导航还可以帮们把VIEW结构生成PSD图或者做快速的切换设备动作。 本文转自 terry_龙 51CTO博客,原文链接:http://blog.51cto.com/terryblog/386568,如需转载请自行联系原作者

优秀的个人博客,低调大师

netapp学习(十二)---Dedup:file-level or block-level??

公司开始搞分布式数据库了,接下来的时间正好有机会接触Hadoop,以前简单的以为Hadoop只是个简单的HDFS,现在才发现Hadoop包括HDFS/MapReduce,再加上Hbase。就有了cloud computing的基础。 这两天就把之前做过的关于DataOntap和Celerra的dedup的实验贴出来,最近也就没时间研究其他东西了。 DataOntap的文档中说它是SIS,即single instance stroage,即单实例存储,所以就是文件级的dedup。下面就来验证它到底是不是SIS? 1、看下现在存储(vol1)的容量,使用101MB 2、101M只包括只有如下文件 3、现在增加2.exe(2.exe和1.exe是完全一样的文件) 4、可以看到由101MB增加到105MB 5、开始做dedup,如果确如文档中所说它是SIS,那么容量应该会减少,至少不是现在的105M DataOnTap2> sis status No status entry found. DataOnTap2> sis on /vol/vol1 SIS for "/vol/vol1" is enabled. Already existing data could be processed by running "sis start -s /vol/vol1". DataOnTap2> sis start -s /vol/vol1 The file system will be scanned to process existing data in /vol/vol1. This operation may initialize related existing metafiles. Are you sure you want to proceed (y/n)? y The SIS operation for "/vol/vol1" is started. DataOnTap2> Sat Oct 8 02:21:27 GMT [DataOnTap2: wafl.scan.start:info]: Starting SIS volume scan on volume vol1. Sat Oct 8 02:21:52 GMT [DataOnTap2: wafl.snap.delete:info]: Snapshot copy sis.5d9cd2b6-e429-11e0-8fc5-005056a5000b on volume vol1 NetApp was deleted by the Data ONTAP function dense_delete_snapshot. The unique ID for this Snapshot copy is (1, 20964). 6、做完SIS后发现容量确实变成了102M 从108404KB减少到104344KB 上面已经证明了DataOntap8确实是SIS,那么会不会是块级别或者是字节级别的dedup呢?为此,有了下面的实验 1、先上传wafl-overview.ppt,容量为103MB 2、再上传wafl-overview-2.ppt(wafl-overview-2.ppt比 wafl-overview.ppt多了2页),做dedup之前大小为103MB,105996KB 3、开始dedup,如果是block-level或byte-level的,那么大小应该经dedup后小于105996KB DataOnTap2> sis start -s /vol/vol1 The file system will be scanned to process existing data in /vol/vol1. This operation may initialize related existing metafiles. Are you sure you want to proceed (y/n)? y The SIS operation for "/vol/vol1" is started. DataOnTap2> Sat Oct 8 03:18:25 GMT [DataOnTap2: wafl.scan.start:info]: Starting SIS volume scan on volume vol1. DataOnTap2> Sat Oct 8 03:18:53 GMT [DataOnTap2: wafl.snap.delete:info]: Snapshot copy sis.5d9cd2b6-e429-11e0-8fc5-005056a5000b on volume vol1 NetApp was deleted by the Data ONTAP function dense_delete_snapshot. The unique ID for this Snapshot copy is (2, 20983). 4、经过dedup并没有改变 通过以上的实验说明,DataOntap8确实是file-level的SIS,并不是block-level或byte-level的。可能有人会有疑问:上面的2个PPT的实验文件太小,可能采用的block-level的技术,而文件大小没有达到block-level的block大小。但是据我所知,如果是block-level的,不管是定长还是不定长,都不会超过上面的412KB吧。所以只要是block-level的,它肯定会进行切分,并删除重复的部分。所以DataOntap8只是file-level的。 下次把celerra的dedup实验贴出来。。。。。 本文转自 taojin1240 51CTO博客,原文链接:http://blog.51cto.com/taotao1240/688699,如需转载请自行联系原作者

优秀的个人博客,低调大师

开源中国iOS客户端学习——(七)MBProgressHUD特效

在开源中国iOS客户端中也用到了MBProgressHUD这个特效,主要作用为应用显示一个过渡的作用,常用于打开一个联网页面加载过程,防止出现假死现象,如果网速慢则告诉用户已经在很努力很努力的加载中。 GitHub上下载地址:https://github.com/jdg/MBProgressHUD 源码中也自带了一个Demo,显示13中动画效果,可以根据需要选取其中特效加以使用,使用方法基本一样;使用的时候只加把MBProgressHUD.h和MBProgressHUD.m拖入工程中,在使用的文件中加上#import"MBProgressHUD.h" 在开源中国iOS客户端中只用到一种特效,当我们选取一条资讯查看详细信息时: 我们在跳转到实现的代码部分,在NewsDetail.m的clickFavorite和viewDidLoad方法中 - (void)clickFavorite:(id)sender { UIBarButtonItem * btn = (UIBarButtonItem *)sender; BOOL isFav = [btn.title isEqualToString:@"收藏此文"]; MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view]; [Tool showHUD:isFav ? @"正在添加收藏":@"正在删除收藏" andView:self.view andHUD:hud]; [[AFOSCClient sharedClient]getPath:isFav ? api_favorite_add : api_favorite_delete parameters:[NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%d", [Config Instance].getUID],@"uid", [NSString stringWithFormat:@"%d", newsID],@"objid", @"4",@"type", nil] success:^(AFHTTPRequestOperation *operation, id responseObject) { [hud hide:YES]; [Tool getOSCNotice2:operation.responseString]; ApiError *error = [Tool getApiError2:operation.responseString]; if (error == nil) { [Tool ToastNotification:operation.responseString andView:self.view andLoading:NO andIsBottom:NO]; return ; } switch (error.errorCode) { case 1: { btnFavorite.title = isFav ? @"取消收藏" : @"收藏此文"; self.singleNews.favorite = !self.singleNews.favorite; } break; case 0: case -2: case -1: { [Tool ToastNotification:[NSString stringWithFormat:@"错误 %@",error.errorMessage] andView:self.view andLoading:NO andIsBottom:NO]; } break; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [hud hide:YES]; [Tool ToastNotification:@"添加收藏失败" andView:self.view andLoading:NO andIsBottom:NO]; }]; } - (void)viewDidLoad { [super viewDidLoad]; self.tabBarItem.title = @"资讯详情"; self.tabBarItem.image = [UIImage imageNamed:@"detail"]; //WebView的背景颜色去除 [Tool clearWebViewBackground:self.webView]; self.singleNews = [[SingleNews alloc] init]; self.navigationController.title = @"资讯详情"; self.webView.delegate = self; [self.webView loadHTMLString:@"" baseURL:nil]; if ([Config Instance].isNetworkRunning) { MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view]; [Tool showHUD:@"正在加载" andView:self.view andHUD:hud]; NSString *url = [NSString stringWithFormat:@"%@?id=%d",api_news_detail, newsID]; [[AFOSCClient sharedClient] getPath:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { [Tool getOSCNotice2:operation.responseString]; [hud hide:YES]; self.singleNews = [Tool readStrNewsDetail:operation.responseString]; if (self.singleNews == nil) { [Tool ToastNotification:@"加载失败" andView:self.view andLoading:NO andIsBottom:NO]; return; } [self loadData:self.singleNews]; //如果有网络 则缓存它 if ([Config Instance].isNetworkRunning) { [Tool saveCache:1 andID:self.singleNews._id andString:operation.responseString]; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [hud hide:YES]; if ([Config Instance].isNetworkRunning) { [Tool ToastNotification:@"错误 网络无连接" andView:self.view andLoading:NO andIsBottom:NO]; } }]; } else { NSString *value = [Tool getCache:1 andID:newsID]; if (value) { self.singleNews = [Tool readStrNewsDetail:value]; [self loadData:self.singleNews]; } else { [Tool ToastNotification:@"错误 网络无连接" andView:self.view andLoading:NO andIsBottom:NO]; } } } 分析viewDidLoad方法, 首先是判断网络是否连通状态,如果是 定义在当前的view中定义一个MBProgressHUD对象,进行初始化 [ToolshowHUD:@"正在加载"andView:self.viewandHUD:hud];是在Tool类里面进行的一次封装,设置MBProgressHUD的显示信息 + (void)showHUD:(NSString *)text andView:(UIView *)view andHUD:(MBProgressHUD *)hud { [view addSubview:hud]; hud.labelText = text;//显示提示 hud.dimBackground = YES;//使背景成黑灰色,让MBProgressHUD成高亮显示 hud.square = YES;//设置显示框的高度和宽度一样 [hud show:YES]; } 然后在用到AFNetWork类库的getPath:parameters:success:failure:方法,嵌套在block块中判断请求的url是否成功,在执行[Tool getOSCNotice2:operation.responseString];这个方法也是封装在Tool类中,封装的是TBXML解析器,如果解析成功立即设置MBProgressHUD隐藏属性[hud hide:YES];如果请求的url不成功直接设置MBProgressHUD隐藏属性[hud hide:YES],再用GCDiscreetNotificationView进行通知“错误 网络无连接”; 本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1208683,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android开发学习:在Eclipse中导入Android项目方法

在Eclipse中导入Android项目方法的具体步骤如下: 1.启动Eclipse,依次选择File---Import,如下图所示: 2.在弹出的Import窗口中选择Existing Projects into Workspace,然后单击Next按钮,如下图所示: 3.在弹出的Import窗口选择Browse按钮,选择要导入项目的位置,如下图所示: 4.单击Finish按钮后,完成整个导入过程,在eclipse中讲显示这个导入的实例,如下如所示 5.需要运行这个项目,依次选择Run---Run Configurations 6.在弹出的窗口中设置标志名,再选择Browse文件功能和项目位置 7.单击Run后开始运行这个项目 本文转自 lingdududu 51CTO博客,原文链接:http://blog.51cto.com/liangruijun/667705

优秀的个人博客,低调大师

iOS学习——iOS网络通信http之NSURLConnection(八)

移动互联网时代,网络通信已是手机终端必不可少的功能。我们的应用中也必不可少的使用了网络通信,增强客户端与服务器交互。这一篇提供了使用NSURLConnection实现http通信的方式。 NSURLConnection提供了异步请求、同步请求两种通信方式。 1、异步请求 iOS5.0 SDK NSURLConnection类新增的sendAsynchronousRequest:queue:completionHandler:方法,从而使iOS5支持两种异步请求方式。我们先从新增类开始。 1)sendAsynchronousRequest iOS5.0开始支持sendAsynchronousReques方法,方法使用如下: - (void)httpAsynchronousRequest{ NSURL *url = [NSURL URLWithString:@"http://url"]; NSString *post=@"postData"; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:postData]; [request setTimeoutInterval:10.0]; NSOperationQueue *queue = [[NSOperationQueue alloc]init]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ if (error) { NSLog(@"Httperror:%@%d", error.localizedDescription,error.code); }else{ NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode]; NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"HttpResponseCode:%d", responseCode); NSLog(@"HttpResponseBody %@",responseString); } }]; } sendAsynchronousReques可以很容易地使用NSURLRequest接收回调,完成http通信。 2)connectionWithRequest iOS2.0就开始支持connectionWithRequest方法,使用如下: - (void)httpConnectionWithRequest{ NSString *URLPath = [NSString stringWithFormat:@"http://url"]; NSURL *URL = [NSURL URLWithString:URLPath]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; [NSURLConnection connectionWithRequest:request delegate:self]; } - (void)connection:(NSURLConnection *)theConnection didReceiveResponse:(NSURLResponse *)response { NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode]; NSLog(@"response length=%lld statecode%d", [response expectedContentLength],responseCode); } // A delegate method called by the NSURLConnection as data arrives. The // response data for a POST is only for useful for debugging purposes, // so we just drop it on the floor. - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data { if (mData == nil) { mData = [[NSMutableData alloc] initWithData:data]; } else { [mData appendData:data]; } NSLog(@"response connection"); } // A delegate method called by the NSURLConnection if the connection fails. // We shut down the connection and display the failure. Production quality code // would either display or log the actual error. - (void)connection:(NSURLConnection *)theConnection didFailWithError:(NSError *)error { NSLog(@"response error%@", [error localizedFailureReason]); } // A delegate method called by the NSURLConnection when the connection has been // done successfully. We shut down the connection with a nil status, which // causes the image to be displayed. - (void)connectionDidFinishLoading:(NSURLConnection *)theConnection { NSString *responseString = [[NSString alloc] initWithData:mData encoding:NSUTF8StringEncoding]; NSLog(@"response body%@", responseString); } connectionWithRequest需要delegate参数,通过一个delegate来做数据的下载以及Request的接受以及连接状态,此处delegate:self,所以需要本类实现一些方法,并且定义mData做数据的接受。 需要实现的方法: 1、获取返回状态、包头信息。 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response; 2、连接失败,包含失败。 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error; 3、接收数据 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data; 4、数据接收完毕 - (void)connectionDidFinishLoading:(NSURLConnection*)connection; connectionWithRequest使用起来比较繁琐,而iOS5.0之前用不支持sendAsynchronousRequest。有网友提出了AEURLConnection解决方案。 AEURLConnection is a simple reimplementation of the API for use on iOS 4. Used properly, it is also guaranteed to be safe against The Deallocation Problem, a thorny threading issue that affects most other networking libraries. 2、同步请求 同步请求数据方法如下: - (void)httpSynchronousRequest{ NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]; NSURLResponse * response = nil; NSError * error = nil; NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; if (error == nil) { // 处理数据 } } 同步请求数据会造成主线程阻塞,通常在请求大数据或网络不畅时不建议使用。 从上面的代码可以看出,不管同步请求还是异步请求,建立通信的步骤基本是一样的: 1、创建NSURL 2、创建Request对象 3、创建NSURLConnection连接。 NSURLConnection创建成功后,就创建了一个http连接。异步请求和同步请求的区别是:创建了异步请求,用户可以做其他的操作,请求会在另一个线程执行,通信结果及过程会在回调函数中执行。同步请求则不同,需要请求结束用户才能做其他的操作。 /** * @author 张兴业 * http://blog.csdn.net/xyz_lmn * iOS入门群:83702688 * android开发进阶群:241395671 * 我的新浪微博:@张兴业TBOW */ 参考: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836-BAJEAIEE http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/ http://kelp.phate.org/2011/06/ios-stringwithcontentsofurlnsurlconnect.html 本文转自xyz_lmn51CTO博客,原文链接: http://blog.51cto.com/xyzlmn/1230731 ,如需转载请自行联系原作者

优秀的个人博客,低调大师

android学习之-TextView内容及颜色的修改方法

主类 packagesucre.android; importandroid.app.Activity; importandroid.content.res.Resources; importandroid.graphics.Color; importandroid.graphics.drawable.Drawable; importandroid.os.Bundle; importandroid.widget.TextView; /** *给TextView变色的两种方法:一是直接读取写好的配置文件,二是在类中获取TextView直接用setBackground**进行修改 *可以对TextView原先的内容进行添加,这里用到了CharSequence *@authorqiaolei * */ publicclassEXT03_02extendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); //获取资源 Resourcesre=getBaseContext().getResources(); //从资源中获取drawable Drawableda=re.getDrawable(R.drawable.red); //将main.xml中定义的myTextViewTest取出 TextViewtv=(TextView)findViewById(R.id.myTextViewTest); //将定义的textview的背景图片换成指定颜色 tv.setBackgroundDrawable(da); //也可以直接设置文本的颜色 tv.setTextColor(Color.BLACK); //对TextView的内容进行修改 //读取字符串hello中的内容 CharSequencestr=getString(R.string.hello); //要进行添加的内容 Stringstr_1="我是后添加上的内容"; //将拼接好的内容赋给原先的TextView tv.setText(str+str_1); } } main.xml <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white" > <TextView android:id="@+id/myTextViewTest" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textColor="@drawable/blue" /> </LinearLayout> color.xml <?xmlversion="1.0"encoding="UTF-8"?> <resources> <colorname="white">#ffffff</color> <colorname="black">#000000</color> <drawablename="red">#ff0000</drawable> <drawablename="blue">#0000ff</drawable> </resources> strings.xml <?xmlversion="1.0"encoding="utf-8"?> <resources> <stringname="hello">HelloWorld,EXT03_02!</string> <stringname="app_name">EXT03_02</string> </resources> 以上是我在看书的时候跟着例子做的,有些东西书上是没有的我就自己加上了,因为自己也是刚接触android开发,所以例子有些简单,但是备份一下,以后用的着。 本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/742803,如需转载请自行联系原作者

优秀的个人博客,低调大师

JMS学习(六)-ActiveMQ的高可用性实现

原文地址:http://www.cnblogs.com/hapjin/p/5663024.html 一,ActiveMQ高可用性的架构 ActiveMQ的高可用性架构是基于Master/Slave 模型的。ActiveMQ总共提供了四种配置方案来配置HA,其中Shared Nothing Master/Slave 在5.8版本之后不再使用了,并在ActiveMQ5.9版本中引入了基于Zookeeper的Replicated LevelDB Store HA方案。 二,Master/Slave架构的配置解释 ①Shared Nothing Master/Slave 该架构最大的特点是: 1)Master 和 Slave各自都单独存储持久化的消息,它们不共享数据。 2)Master收到持久化消息时,需要先同步(sync)给Slave之后,才向Producer发送ACK确认。 3)只有Master负责Client的请求,Slave不接收Client请求。Slave连接到Master,负责备份消息。 4)Master出现故障,Slave有两种处理方式:自己成为Master;关闭(停服务)---根据具体配置而定。 5)Master 与 Slave之间可能会出现“Split Brain”现象。比如:Master本身是正常的,但是Master与Slave之间的网络出现故障,网络故障导致Slave认为Master已经宕机,因为它自己会成为Master(根据配置:shutdownOnMasterFailure)。此时,对Client而言,就会存在两个Master。 6)Slave 只能同步它连接到Master之后的消息。在Slave连接到Master之前Producer向Master发送的消息将不会同步给Slave,这可以通过配置(waitForSlave)参数,只有当Slave也启动之后,Master才开始初始化TransportConnector接受Client的请求(Producer的请求) 7)如果Master 或者 Slave其中之一宕机,它们之间不同步的消息 无法 自动进行同步,此时只能手动恢复不同步的消息了。也就是说:“ActiveMQ没有提供任何有效的手段,能够让master与slave在故障恢复期间,自动进行数据同步” 8)对于非持久化消息,并不会同步给Slave。因此,Master宕机,非持久化消息会丢失。 关于ShareNothing 高可用配置的一点理解: 由上面的第2)步可知:Producer向Master发消息之后,Master需要将消息同步给Slave之后,才向Producer返回确认ACK。因此,对Producer的响应有一定的延时。 如果为了保证快速响应,即Producer给Master发消息之后,Master收到了消息立即给Producer回复,然后再在后台把消息同步给Slave。这又会造成数据不一致性问题。 因为,如果Master收到了消息立即给Producer回复之后,Master还未来得及向Slave同步就宕机了,如果此条消息还在Master内存中,则Master宕机后消息就丢失了。如果Master收到Producer的消息,先写入磁盘,然后再向Producer返回确认ACK,然后再在后台与Slave同步,那么Master就需要标记每条消息是否已经成功同步到了Slave,若消息还未同步到Slave,则Master重启恢复后,需要立即同步Slave。只有当Slave成功同步了所有的Master上的消息之后,才能上线。这也无法实现 automatic failover。 关于一个很好的高可靠性解决方案:可参考 Hadoop HA中的QJM机制。其核心就是:1)采用集群,能容忍不超过大多数机器的失效;2)数据只写大多数机器就返回确认,保证Client快速的响应能力;3)数据在后台在异步同步到集群所有的机器,从而保证高可用。 这里的Master--Slave机制中,只有一台Slave,并不是Slave集群(见上面结构图)。Master宕机,或者Slave宕机后,都会给整个服务造成极大的风险,并没有像Hadoop HA中的那样能够容忍“不超过大多数机器失效”的保证,即没有做到真正的高可用性。 还可能出现“双主”问题。即上面提到的“Split Brian”现象。 ②Shared Database Master/Slave 这是很常用的一种架构。“共享存储”,意味着Master与Slave之间的数据是共享的。 那如何避免冲突呢?通过争夺数据库表的排他锁,只有Master有锁,未获得锁的自动成为Slave。 ActiveMQ Message Broker uses a relational database, it grabs an exclusive lock on a table ensuring that no other ActiveMQ broker can access the database at the same time 对于“共享存储”而言,只会“共享”持久化消息。对于非持久化消息,它们是在内存中保存的。可以通过配置(forcePersistencyModeBrokerPluginpersistenceFlag)属性强制所有的消息都持久化。 当Master宕机后,Slave可自动接管服务成为Master。由于数据是共享的,因此Master和Slave之间不需要进行数据的复制与同步。Slave之间通过竞争锁来决定谁是Master。 ③Shared File system Master/Slave 这种方式和共享数据库存储原理基本一样,(文件系统也有文件锁),故不详细介绍。 ④最近的Replicated LevelDB Store 1)这种方式使用Zookeeper选举Master。要进行选举,则需要多数派的“参与者”。因为Replicated LevelDB Store中有多个Broker,从多个Broker中选举出一个成为Master,其他的则成为Slave。只有Master接收Client的连接,Slave负责连接到Master,并 接收( 同步方式、异步方式)Master上的数据。 The elected master broker node starts and accepts client connections. The other nodes go into slave mode and connect the the master and synchronize their persistent state /w it. 以上也表明:每个Broker都是单独存储数据的。因为Master要把新的数据复制到Slave上。从这个角度看:称这种方式为“Share Storage”有点不合适。 2)Quorum机制的又一应用 假设有3个Broker,那么选举时至少需要两个Broker同意(大多数)之后,才能选出Master。此外,只需要当新消息复制到大多数Broker上时,就可以给Producer返回ACK。其他少数Broker则可以在后台以异步方式复制新的消息。 All messaging operations which require a sync to disk will wait for the update to be replicated to a quorum of the nodes before completing. So if you configure the store with replicas="3" then the quorum size is (3/2+1)=2. The master will store the update locally and wait for 1 other slave to store the update before reporting success. 比如说:一共有3个Broker,一个Master,二个Slave。当新消息到达Master时,Master需要将消息同步到其中一台Slave之后,才能向Producer发送ACK确认此次消息成功发送。 而剩下的另一台Slave,则可以在后台以异步方式复制这个新消息。此外,还能容忍一台Slave宕机。(能容忍不超过大多数的Broker宕机) 这种设计要求,可以保证集群中消息的可靠性,只有当(replicas/2 + 1)个节点物理故障,才会有丢失消息的风险。另外,也提高了一定的响应性,因为它不需要将消息同步到所有的Slave上,而只需要同步到大多数Broker上。 3)以何种标准判断谁是Master,谁是Slave呢? 【选举将会根据“消息日志的版本戳”、“权重"的大小决定,即“版本戳”越大(数据最新)、权重越高的broker优先成为master,其他broker作为slave并跟随master。】 三,参考资料 分布式系统理论之Quorum机制 https://activemq.apache.org/artemis/docs/1.0.0/ha.html Replicated LevelDB Store HA官方文档 ActiveMQ与HA架构(master/slave) 本文转自hapjin博客园博客,原文链接:http://www.cnblogs.com/hapjin/p/5663024.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册