在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Java语言基础 → java Netty 框架例子源码

java Netty 框架例子源码

Java语言基础

下载此实例
  • 开发语言:Java
  • 实例大小:35.79M
  • 下载次数:1050
  • 浏览次数:3074
  • 发布时间:2014-11-10
  • 实例类别:Java语言基础
  • 发 布 人:zhou_long1212
  • 文件格式:.rar
  • 所需积分:0
 相关标签: Netty

实例介绍

【实例简介】Netty 提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户端程序。

【实例截图】

【核心代码】


package com.shadow.mvc.main.view.struts;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.stereotype.Component;

import com.danga.MemCached.MemCachedClient;
import com.shadow.mvc.base.view.IAction;
import com.shadow.mvc.domain.model.Page;
import com.shadow.mvc.domain.model.Service;
import com.shadow.mvc.main.domain.Brand;
import com.shadow.mvc.main.domain.Group;
import com.shadow.mvc.main.domain.User;
import com.shadow.mvc.main.service.GroupService;
import com.shadow.mvc.main.service.UserService;
import com.shadow.mvc.support.view.ActionSupport;
import com.shadow.util.base.Utils;
import com.shadow.util.common.FreemarkerUtil;

/**
 * 用户模块控制实现
 * 
 * @author shadow
 * 
 */
@SuppressWarnings("serial")
@Component("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport implements IAction {

	private UserService userService;
	private GroupService groupService;
	private SessionRegistry sessionRegistry;

	private User user;
	private String array;

	private List<Group> allotGroup;
	private List<Group> notAllotGroup;

	private String language;

	private Service service;

	private Page<User> page;

	private MemCachedClient memCachedClient;

	// 检测用户名是否存在
	public String checkUser() {
		service = this.userService.checkUser(user.getUsername());
		flush(toJSON(service));
		return NONE;
	}

	public String add() {
		service = this.userService.save(user);
		flush(toJSON(service));
		return NONE;
	}

	@Override
	public String edit() {
		service = this.userService.modify(user);
		flush(toJSON(service));
		return NONE;
	}

	public String findById() {
		user = (User) this.userService.findById(user).getValue();
		return "findById";
	}

	@SuppressWarnings("unchecked")
	public String findByIdForAllot() {
		user = (User) this.userService.findById(user).getValue();
		allotGroup = (List<Group>) this.groupService.findAllotGroup(user, 1)
				.getValue();
		notAllotGroup = (List<Group>) this.groupService.findAllotGroup(user, 2)
				.getValue();
		return "findByIdForAllot";
	}

	@SuppressWarnings("unchecked")
	public String pageTotal() {
		Integer total = ((Page<Brand>) this.userService
				.findForPage(getParams()).getValue()).getTotal();
		flush(total);
		return NONE;
	}

	@SuppressWarnings("unchecked")
	public String page() {
		page = (Page<User>) this.userService.findForPage(getParams())
				.getValue();
		return "page";
	}

	public String removeById() {
		service = this.userService.removeById(user);
		flush(toJSON(service));
		return NONE;
	}

	public String removeForAll() {
		service = this.userService.removeForAll(array);
		flush(toJSON(service));
		return NONE;
	}

	/** 测试MemCachedClient */
	public void testMemCachedClient() {
		memCachedClient.set("key", "我是存放起来的值");
		System.out.println("通过memcached获取的值: "   memCachedClient.get("key"));
	}

	/** 统计在线人数 */
	public void onlineUsers() {
		System.out
				.println("当前用户数:"   sessionRegistry.getAllPrincipals().size());
	}

	/** 把当前用户踢出系统 */
	public void shotOff() {
		System.out.println(sessionRegistry.getAllPrincipals().size()
				  "___________");
		// 遍历所有用户
		for (Object o : sessionRegistry.getAllPrincipals()) {
			User user = (User) o;
			System.out.println(user.getId()   "__"   user.getUsername());
			for (SessionInformation information : sessionRegistry
					.getAllSessions(o, false)) {
				information.expireNow();
				sessionRegistry.removeSessionInformation(information
						.getSessionId());
			}
		}
	}

	public void test() {

	}

	/** 多语言测试 */
	public String language() {
		Utils.ContextUtil.setLocale(Utils.LanguageUtil.getLocale(language));
		fillTextParams();
		return "language";
	}

	public void test2() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("message", "这是由FREEMARKER生成的HTML!");
		String url = FreemarkerUtil.getInstance().creat(
				"WEB-INF/ftl/index.html", "sss/sss", "aabs.html", params);
		System.out.println(url);
	}

	public String welcome() {
		return "welcome";
	}

	public String info_login() {
		user = (User) Utils.SecurityUtil.getUserDetails();
		return "info_login";
	}

	public String info_own() {
		user = (User) Utils.SecurityUtil.getUserDetails();
		return "info_own";
	}

	public String logout() {
		return "logout";
	}

	// ======================SET,GET======================

	public String getArray() {
		return array;
	}

	public void setArray(String array) {
		this.array = array;
	}

	public SessionRegistry getSessionRegistry() {
		return sessionRegistry;
	}

	@Resource(name = "sessionRegistry")
	public void setSessionRegistry(SessionRegistry sessionRegistry) {
		this.sessionRegistry = sessionRegistry;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	@Resource(name = "userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public GroupService getGroupService() {
		return groupService;
	}

	@Resource(name = "groupService")
	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}

	public List<Group> getAllotGroup() {
		return allotGroup;
	}

	public void setAllotGroup(List<Group> allotGroup) {
		this.allotGroup = allotGroup;
	}

	public List<Group> getNotAllotGroup() {
		return notAllotGroup;
	}

	public void setNotAllotGroup(List<Group> notAllotGroup) {
		this.notAllotGroup = notAllotGroup;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	public Page<User> getPage() {
		return page;
	}

	public void setPage(Page<User> page) {
		this.page = page;
	}

	public MemCachedClient getMemCachedClient() {
		return memCachedClient;
	}

	@Resource(name = "memCachedClient")
	public void setMemCachedClient(MemCachedClient memCachedClient) {
		this.memCachedClient = memCachedClient;
	}

} 


标签: Netty

实例下载地址

java Netty 框架例子源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 jackjjjjj 发表于: 2017-03-19 11:22 12
有搭建的教程么

支持(0) 盖楼(回复)

第 2 楼 lyf001 发表于: 2017-09-08 14:20 54
有搭建?

支持(0) 盖楼(回复)

第 3 楼 compcloud0043 发表于: 2018-04-01 23:01 22
怎么没有看到使用netty的地方?

支持(0) 盖楼(回复)

第 4 楼 wanlifeng 发表于: 2020-05-17 16:19 06
资料不错,正需要

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有4条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警