memcached+狀態模式+工廠方法使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace memcached
{
public interface IStates
{
bool PreProduction(Context context,string FlowNo); //上機
bool PostProduction(Context context, string FlowNo);//下機
bool MaterialImput(Context context, string FlowNo);//物料錄入
} public class Context
{
public Context(IStates state)
{
this.currentState = state;
} private string FlowNo; public string flowno {
get { return FlowNo; }
set { FlowNo = value; }
} private IStates currentState;
public IStates CurrentState
{
//set
//{
// currentState = value;
//} get { return currentState; }
set { currentState = value; }
} /// <summary>
/// 执行動作
/// </summary>
public virtual bool PreProduction() { return this.currentState.PreProduction(this, flowno); }
public virtual bool PostProduction() { return this.currentState.PostProduction(this,flowno); }
public virtual bool MaterialImput() { return this.currentState.MaterialImput(this,flowno); }
} /// <summary>
/// 空閒
/// </summary>
public class OpenState : IStates
{
public bool PreProduction(Context context,string flowno)
{
Console.WriteLine("FLOW卡上機成功");
AMemcached.cache.Replace(flowno, "Opening");
return true; } public bool PostProduction(Context context, string flowno)
{
Console.WriteLine("FLOW卡還未物料錄入,無法下機");
return false;
} public bool MaterialImput(Context context,string flowno)
{
Console.WriteLine("FLOW卡未上機不能進行物料錄入");
return false;
}
} /// <summary>
/// 完成
/// </summary>
public class CloseState : IStates
{
public bool PreProduction(Context context,string flowno)
{
Console.WriteLine("FLOW卡正在上機中,無法重複上機");
return false;
} public bool PostProduction(Context context, string flowno)
{
Console.WriteLine("物料已錄入,成功下機");
//context.CurrentState = new OpenState();
AMemcached.cache.Replace(flowno, "OpenState");
var stateq = AMemcached.cache.Get(flowno);
return true;
} public bool MaterialImput(Context context, string flowno)
{
Console.WriteLine("物料已錄入,無法重複錄入");
return false;
}
} /// <summary>
/// 生產中
/// </summary>
public class Opening : IStates
{
public bool PreProduction(Context context,string flowno)
{
Console.WriteLine("FLOW卡正在上機中,無法重複上機");
return false;
} public bool PostProduction(Context context, string flowno)
{
Console.WriteLine("物料還未錄入,無法下機");
return false;
} public bool MaterialImput(Context context, string flowno)
{
Console.WriteLine("FLOW已上機,物料成功錄入");
// context.CurrentState = new CloseState();
AMemcached.cache.Replace(flowno, "CloseState");
var stateq = AMemcached.cache.Get(flowno);
return true;
}
}
}
using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace memcached
{
class Program
{
static void Main(string[] args)
{
var state = AMemcached.cache.Get(DJ);
Context check = new Context(Activator.CreateInstance(Type.GetType("memcached"+"."+ state)) as IStates);
check.flowno = DJ;
check.PreProduction();//上機 var states = AMemcached.cache.Get(DJ);
check = new Context(Activator.CreateInstance(Type.GetType("memcached" + "." + states)) as IStates);
check.flowno = DJ;
check.PostProduction();//下機 var statee = AMemcached.cache.Get(DJ);
check = new Context(Activator.CreateInstance(Type.GetType("memcached" + "." + statee)) as IStates);
check.flowno = DJ;
check.MaterialImput();//物料錄入 Console.ReadKey();
}
} public class AMemcached
{
public static MemcachedClient cache;
static AMemcached()
{
string[] servers = { "192.168.1.18:11211" };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
//设置服务器列表
pool.SetServers(servers);
//各服务器之间负载均衡的设置比例
pool.SetWeights(new int[] { });
//初始化时创建连接数
pool.InitConnections = ;
//最小连接数
pool.MinConnections = ;
//最大连接数
pool.MaxConnections = ;
//连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉
pool.MaxIdle = * * * ;
//socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态
pool.SocketConnectTimeout = ;
//通讯的超市时间,下面设置为3秒(单位ms),.Net版本没有实现
pool.SocketTimeout = * ;
//维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程
pool.MaintenanceSleep = ;
//设置SocktIO池的故障标志
pool.Failover = true;
//是否对TCP/IP通讯使用nalgle算法,.net版本没有实现
pool.Nagle = false;
//socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。
pool.MaxBusy = * ;
pool.Initialize();
cache = new MemcachedClient();
//是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式
cache.EnableCompression = false;
//压缩设置,超过指定大小的都压缩
//cache.CompressionThreshold = 1024 * 1024;
}
} [Serializable]
public class MpsFlowData
{
public string productno { get; set; }
public string seqno { get; set; }
public string keyno { get; set; }
public string state { get; set;} }
}
memcached+狀態模式+工廠方法使用的更多相关文章
- java-設計模式-工場方法
工廠方法: 一种创建型设计模式, 其在父类中提供一个创建对象的方法, 允许子类决定实例化对象的类型. 定义一个创建产品对象的工厂接口,将产品对象的实际创建工作推迟到具体子工厂类当中. 这满足创建型 ...
- 簡單工廠模式-之-什麼是產品線 And 抽象工廠模式-之-什麼是產品族
簡單工廠模式-之-什麼是產品線 簡單工廠模式中,有一個概念就是使用了多層次的產品結構,那麼什麼是產品結構或者說什麼是產品線? 假定我們有一個基準的產品標準Product,那麼所有繼承該基類或者傳遞基類 ...
- [實現DDD] 第11章 工廠
創建過程中須考慮一些重要細節, 否則所創建的聚合將處於不正確的狀態, 使用適當的工廠方法可以確保這一點, 而客戶端只需輸入基本的參數(通常是值對象), 另外, 工廠能更好地表達出通用語言, 使團隊成員 ...
- Flater-Provide狀態管理
參考來源:http://www.jspang.com/posts/2019/03/01/flutter-shop.html#%E7%AC%AC24%E8%8A%82%EF%BC%9Aprovide%E ...
- Win10還原成最乾淨的狀態 不必重灌
系統不穩定時我們想到的第一個選擇就是重灌,如果你的作業系統是win10將會有另外一個新選擇,就是透過程式進行還原,讓你的電腦回到剛安裝時的清爽. 工具資訊 [軟體名稱]微軟 Refresh Windo ...
- Win10還原成最乾淨的狀態
系統不穩定時我們想到的第一個選擇就是重灌,如果你的作業系統是win10將會有另外一個新選擇,就是透過程式進行還原,讓你的電腦回到剛安裝時的清爽. 工具資訊 [軟體名稱]微軟 Refresh Windo ...
- 組裝工廠設置IQC的目的
在電子組裝工廠的組織裡,一般都會有 IQC (Incoming Quality Control) 這個單位,台灣稱之為「入(進)料管控」,大陸稱之為「來料管控」,其最主要目的在攔檢所有買進材料是否符合 ...
- [Gem] AASM 狀態機
@(Ruby on Rails)[rails, gem] 1234 # AASM is a continuation of the acts-as-state-machine rails plugin ...
- 檢查RAC狀態
1.使用srvctl工具檢查RAC當前配置和狀態 $ srvctl config database -h Displays the configuration for the database. Us ...
随机推荐
- 【Beta】Daily Scrum Meeting——Day2
站立式会议照片 1.本次会议为第一次Meeting会议: 2.本次会议在中午12:00,在图书馆一楼楼道召开,本次会议为30分钟讨论今天要完成的任务以及接下来的任务安排. 燃尽图 每个人的工作分配 成 ...
- 第1周-java作业总结与建议
1. 本周作业简评与建议 存在的问题: 这周的作业普遍存在一个格式混乱的问题.请认真学习Markdown,我们后面的作业都要使用Markdown.Markdown学习请参考http://group.c ...
- linux下修改rm命令防止误删除
前言:相信很多朋友都遇到过在linux下用rm命令误删除文件的时候,此刻的心中仿佛有无数的羊驼在奔腾.那么怎么防止这种情况发生呢?当然是有方法的,我们可以写一个shell脚本,改变一下rm命令的作用. ...
- Activiti第三篇【连接、排他网关、指定任务处理人、组任务】
连线 上面我们已将学过了流程变量了,可以在[任务服务.运行时服务.流程开始.完成某个任务时设置流程变量],而我们的连接就是流程变量的实际应用了-. 定义流程图 我们并不是所有的流程都是按一条的路径来走 ...
- bookStore第二篇【图书模块、前台页面】
图书模块 分析 在设计图书管理的时候,我们应该想到:图书和分类是有关系的.一个分类可以对应多本图书. 为什么要这样设计?这样更加人性化,用户在购买书籍的时候,用户能够查看相关分类后的图书,而不是全部图 ...
- 我和Python
记不得是年,我在网易云课堂上乱逛,看到了哈佛大学的<计算机编程导论>,这门课讲的正好是Python,讲的啥内容已经记不得多少了,因为是全英文教学,我只能慢慢的看字幕,一集得看个好几遍. 我 ...
- C# 反射结构体struct的一个坑
今天代码用到了反射赋值,代码是这样写的: var objtype = obj.GetType(); var Fieldinfo = objtype.GetField("I64"); ...
- 关于maven中一些问题的解决尝试
在maven中会遇到很多问题,pom.xml啊,数据库没有自动建表等等. 需要先把运行项目,所依赖的jar项目install安装一下,然后Maven --> update project 一下. ...
- ng-model值字符串转数值型(convertToNumber directive)
<select ng-model="model.id" convert-to-number> <option value="0">Zer ...
- 初识Hibernate之环境搭建
相信所有做后端的程序员同行们,没有不知道Hibernate大名的.这是一个经典的轻量级Java EE持久层的解决方案,它使得我们程序员能以面向对象的思维操作传统的关系型数据库,这也是其存在的 ...