It is obviously an attack which falls upon your nervous system through the subconscient. It comes in sleep because in the waking consciousness you are more on your guard and able to react against attacks. Usually this kind of dream and discharge comes when the physical consciousness is in a tamasic condition through fatigue or strain or any other cause, in a heavy sleep or under a stress of inertia.
The first thing to do is to reject the after consequences as you have done this time, for you say you do not feel any weakness, but rather as if nothing had happened. It is not at all inevitable that one should feel weakness after a dream of this kind and a discharge; it is only by a habitual association in the physical mind that these forces can bring these reactions of nervous weakness.
As for preventing the discharge, it can be done by becoming more conscious in sleep. You were conscious of all that happened, but you must besides develop the power of a conscious will which sees what is going to happen and interferes to prevent it, either by waking in time or by stopping the dream or prohibiting the discharge. All this is perfectly possible, it is a matter of habit and a little persistence.
There is a force of purity, not the purity of the moralist, but an essential purity of spirit, in the very substance of the being. When that comes, then sex-waves either cannot approach or they pass without imparting any impulse, without touching anywhere.