コード例 #1
0
func (cw ConnectionWebSockets) Send(msgtype int64, codec string, msg []byte) (err error) {
	m := websocketMsg{"AursirRT", msgtype, codec, msg}
	encoder := util.GetCodec("JSON")

	p, _ := encoder.Encode(m)
	err = websocket.Message.Send(cw.ws, p)
	return
}
コード例 #2
0
func (p ParseMessageProccesor) Process() {

	decoder := util.GetCodec(p.Codec)
	if decoder == nil {
		return
	}
	printDebug("Processing message", p.Type)
	switch p.Type {
	case messages.LEAVE:
		var np LeaveProcessor
		np.AppId = p.AppId
		np.GenericProcessor = processor.GetGenericProcessor()

		p.SpawnProcess(np)

	case messages.ADD_EXPORT:
		var m messages.AddExportMessage
		decoder.Decode(p.Msg, &m)
		var np AddExportProcessor
		np.AppId = p.AppId
		np.AddExportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.UPDATE_EXPORT:
		var m messages.UpdateExportMessage
		decoder.Decode(p.Msg, &m)
		var np UpdateExportProcessor
		np.AppId = p.AppId
		np.UpdateExportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.REMOVE_EXPORT:
		var m messages.RemoveExportMessage
		decoder.Decode(p.Msg, &m)
		var np RemoveExportProcessor
		np.AppId = p.AppId
		np.RemoveExportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.REMOVE_IMPORT:
		var m messages.RemoveImportMessage
		decoder.Decode(p.Msg, &m)
		var np RemoveImportProcessor
		np.AppId = p.AppId
		np.RemoveImportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.ADD_IMPORT:
		var m messages.AddImportMessage
		decoder.Decode(p.Msg, &m)
		var np AddImportProcessor
		np.AppId = p.AppId
		np.AddImportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.UPDATE_IMPORT:
		var m messages.UpdateImportMessage
		decoder.Decode(p.Msg, &m)
		var np UpdateImportProcessor
		np.AppId = p.AppId
		np.UpdateImportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	case messages.LISTEN:
		var m messages.ListenMessage
		decoder.Decode(p.Msg, &m)
		var np StartListenProcessor
		np.AppId = p.AppId
		np.StartListenMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	case messages.STOP_LISTEN:
		var m messages.StopListenMessage
		decoder.Decode(p.Msg, &m)
		var np StopListenProcessor
		np.AppId = p.AppId
		np.StopListenMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.REQUEST:
		var m messages.Request
		decoder.Decode(p.Msg, &m)
		var np RequestProcessor
		np.AppId = p.AppId
		np.Request = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	case messages.RESULT:
		var m messages.Result
		decoder.Decode(p.Msg, &m)
		printDebug("RESZ", m)
		var np ResultProcessor
		np.AppId = p.AppId
		np.Result = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	}

}
コード例 #3
0
func (p DockProcessor) Process() {
	if p.Connection != nil {
		decoder := util.GetCodec(p.Codec)
		if decoder == nil {
			return
		}
		var dmsg messages.DockMessage
		err := decoder.Decode(p.DockMessage, &dmsg)
		if err != nil {
			return
		}
		app := types.GetApp(p.AppId, p.GetAgent())
		ok := app.Create(dmsg, p.Connection)
		if ok {
			app.Lock()
			defer app.Unlock()
			conn, _ := app.GetConnection()
			err = conn.Init()
			if err != nil {
				return
			}
			if app.IsNode() {
				var sp SendMessageProcessor
				sp.App = app
				sp.Msg = messages.DockMessage{"runtime", []string{"JSON"}, true}
				sp.GenericProcessor = processor.GetGenericProcessor()
				p.SpawnProcess(sp)
			}

		}

		var sp SendMessageProcessor
		sp.App = app
		sp.Msg = messages.DockedMessage{ok}
		sp.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(sp)

		if ok && app.IsNode() {
			for _, localapp := range types.GetApps(p.GetAgent()) {
				for _, imp := range localapp.GetImports() {
					var m messages.AddImportMessage
					m.AppKey = imp.GetAppKey().GetKey()
					m.Tags = imp.GetTagNames()
					m.ImportId = imp.GetId()
					var sp SendMessageProcessor
					sp.App = app
					sp.Msg = m
					sp.GenericProcessor = processor.GetGenericProcessor()
					p.SpawnProcess(sp)
				}
				for _, exp := range localapp.GetExports() {
					var m messages.AddExportMessage
					m.AppKey = exp.GetAppKey().GetKey()
					m.Tags = exp.GetTagNames()
					m.ExportId = exp.GetId()
					var sp SendMessageProcessor
					sp.App = app
					sp.Msg = m
					sp.GenericProcessor = processor.GetGenericProcessor()
					p.SpawnProcess(sp)
				}
			}
		}
	}

}